Raycaster

Mount.java

Mar 1st, 2021
693
315 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.planet_ink.coffee_mud.Commands;
  2. import com.planet_ink.coffee_mud.core.interfaces.*;
  3. import com.planet_ink.coffee_mud.core.*;
  4. import com.planet_ink.coffee_mud.core.collections.*;
  5. import com.planet_ink.coffee_mud.Abilities.interfaces.*;
  6. import com.planet_ink.coffee_mud.Areas.interfaces.*;
  7. import com.planet_ink.coffee_mud.Behaviors.interfaces.*;
  8. import com.planet_ink.coffee_mud.CharClasses.interfaces.*;
  9. import com.planet_ink.coffee_mud.Commands.interfaces.*;
  10. import com.planet_ink.coffee_mud.Common.interfaces.*;
  11. import com.planet_ink.coffee_mud.Exits.interfaces.*;
  12. import com.planet_ink.coffee_mud.Items.interfaces.*;
  13. import com.planet_ink.coffee_mud.Libraries.interfaces.*;
  14. import com.planet_ink.coffee_mud.Locales.interfaces.*;
  15. import com.planet_ink.coffee_mud.MOBS.interfaces.*;
  16. import com.planet_ink.coffee_mud.Races.interfaces.*;
  17.  
  18. import java.util.*;
  19.  
  20. /*
  21.    Copyright 2004-2021 Bo Zimmerman
  22.  
  23.    Licensed under the Apache License, Version 2.0 (the "License");
  24.    you may not use this file except in compliance with the License.
  25.    You may obtain a copy of the License at
  26.  
  27.        http://www.apache.org/licenses/LICENSE-2.0
  28.  
  29.    Unless required by applicable law or agreed to in writing, software
  30.    distributed under the License is distributed on an "AS IS" BASIS,
  31.    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  32.    See the License for the specific language governing permissions and
  33.    limitations under the License.
  34. */
  35. public class Mount extends StdCommand
  36. {
  37.     public Mount()
  38.     {
  39.     }
  40.  
  41.     private final String[]  access  = I(new String[] { "MOUNT", "BOARD", "RIDE", "M" });
  42.  
  43.     @Override
  44.     public String[] getAccessWords()
  45.     {
  46.         return access;
  47.     }
  48.  
  49.     @Override
  50.     public boolean execute(final MOB mob, List<String> commands, final int metaFlags)
  51.         throws java.io.IOException
  52.     {
  53.         final List<String> origCmds=new XVector<String>(commands);
  54.         if(commands.size()<2)
  55.         {
  56.             CMLib.commands().postCommandFail(mob,origCmds,L("@x1 what?",(commands.get(0))));
  57.             return false;
  58.         }
  59.         final String cmd=commands.remove(0).toString();
  60.         Environmental recipient=null;
  61.         final List<Rideable> possRecipients=new ArrayList<Rideable>();
  62.         for(int m=0;m<mob.location().numInhabitants();m++)
  63.         {
  64.             final MOB M=mob.location().fetchInhabitant(m);
  65.             if((M!=null)&&(M instanceof Rideable))
  66.                 possRecipients.add((Rideable)M);
  67.         }
  68.         for(int i=0;i<mob.location().numItems();i++)
  69.         {
  70.             final Item I=mob.location().getItem(i);
  71.             if((I!=null)&&(I instanceof Rideable))
  72.                 possRecipients.add((Rideable)I);
  73.         }
  74.         Rider RI=null;
  75.         if(commands.size()>1)
  76.         {
  77.             final Item I=mob.location().findItem(null,commands.get(0));
  78.             if(I!=null)
  79.             {
  80.                 commands.remove(0);
  81.                 // this caused re-mounting to occur as if the item was never mounted to anything to begin with.
  82.                 //I.setRiding(null); // why do you get to dismount without a message every time you specify an item to mount?
  83.                 RI=I;
  84.             }
  85.             if(RI==null)
  86.             {
  87.                 final MOB M=mob.location().fetchInhabitant(commands.get(0));
  88.                 if(M!=null)
  89.                 {
  90.                     if(!CMLib.flags().canBeSeenBy(M,mob))
  91.                     {
  92.                         CMLib.commands().postCommandFail(mob,origCmds,L("You don't see @x1 here.",(commands.get(0))));
  93.                         return false;
  94.                     }
  95.                     if(((!CMLib.flags().isBoundOrHeld(M))&&(!M.willFollowOrdersOf(mob)))
  96.                     &&(M != mob))
  97.                     {
  98.                         CMLib.commands().postCommandFail(mob,origCmds,L("Only the bound or servants can be mounted unwillingly."));
  99.                         return false;
  100.                     }
  101.                     RI=M;
  102.                     RI.setRiding(null);
  103.                     commands.remove(0);
  104.                 }
  105.             }
  106.         }
  107.         if(commands.get(0).equalsIgnoreCase("self")
  108.         &&(mob instanceof Rideable))
  109.             recipient=mob;
  110.         if(recipient==null)
  111.             recipient=CMLib.english().fetchEnvironmental(possRecipients,CMParms.combine(commands,0),true);
  112.         if(recipient==null)
  113.             recipient=CMLib.english().fetchEnvironmental(possRecipients,CMParms.combine(commands,0),false);
  114.         if(recipient==null)
  115.             recipient=mob.location().fetchFromRoomFavorMOBs(null,CMParms.combine(commands,0));
  116.         if((recipient==null)||(!CMLib.flags().canBeSeenBy(recipient,mob)))
  117.         {
  118.             CMLib.commands().postCommandFail(mob,origCmds,L("You don't see '@x1' here.",CMParms.combine(commands,0)));
  119.             return false;
  120.         }
  121.         if((recipient instanceof BoardableShip)
  122.         &&(cmd.toUpperCase().startsWith("B")))
  123.         {
  124.             final Command C=CMClass.getCommand("Enter");
  125.             if(C!=null)
  126.             {
  127.                 commands=new XVector<String>(origCmds);
  128.                 commands.set(0,"ENTER");
  129.                 return C.execute(mob, commands, metaFlags);
  130.             }
  131.         }
  132.  
  133.         String mountStr=null;
  134.         if(recipient instanceof Rideable)
  135.         {
  136.             if(RI!=null)
  137.                 mountStr=L("<S-NAME> mount(s) <O-NAME> onto <T-NAMESELF>.");
  138.             else
  139.                 mountStr="<S-NAME> "+((Rideable)recipient).mountString(CMMsg.TYP_MOUNT,mob)+" <T-NAMESELF>.";
  140.         }
  141.         else
  142.         {
  143.             if(RI!=null)
  144.                 mountStr=L("<S-NAME> mount(s) <O-NAME> to <T-NAMESELF>.");
  145.             else
  146.                 mountStr=L("<S-NAME> mount(s) <T-NAMESELF>.");
  147.         }
  148.         final CMMsg msg=CMClass.getMsg(mob,recipient,RI,CMMsg.MSG_MOUNT,mountStr);
  149.         if(mob.location().okMessage(mob,msg))
  150.             mob.location().send(mob,msg);
  151.         return false;
  152.     }
  153.  
  154.     @Override
  155.     public double combatActionsCost(final MOB mob, final List<String> cmds)
  156.     {
  157.         return CMProps.getCommandCombatActionCost(ID());
  158.     }
  159.  
  160.     @Override
  161.     public double actionsCost(final MOB mob, final List<String> cmds)
  162.     {
  163.         return CMProps.getCommandActionCost(ID());
  164.     }
  165.  
  166.     @Override
  167.     public boolean canBeOrdered()
  168.     {
  169.         return true;
  170.     }
  171. }
  172.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×