public static void executeUnequipCommand(Monster monster, MonsterCommand command, Quinoa quinoa) { String itemID = command.getParameter("itemID"); Item itemToEquip = monster.inventory.getItem(itemID); //Find the slot that the item is equiped in ItemSlot equipSlot = ItemSlot.NULL; foreach (ItemSlot tempSlot in Enum.GetValues(typeof(ItemSlot)).Cast<ItemSlot>()) { Item testItem = monster.inventory.getItem(tempSlot); if(testItem != null && testItem.ID.Equals(itemID)) { equipSlot = tempSlot; } } if(equipSlot != ItemSlot.NULL) { if(!monster.inventory.Full) { Item newItem = (Item)itemToEquip.CopyObject(); monster.inventory.equipItem(null, equipSlot); if(!monster.inventory.stackItem(newItem)) { monster.inventory.addItem(newItem); } if(isPlayer(monster)) { quinoa.getMessageManager().addMessage("Unequiped " + EnumUtil.EnumName<ItemClass>(newItem.itemClass) + "."); } } else { if(isPlayer(monster)) { quinoa.getMessageManager().addMessage("No space to unequip that."); } } } }
public static void executeMoveCommand(Monster monster, MonsterCommand command, Quinoa quinoa) { Region region = quinoa.getCurrentRegionHeader().getRegion(); Direction direction = (Direction) Enum.Parse(typeof(Direction), command.getParameter("direction")); monster.facing = direction; int newX = monster.x; int newY = monster.y; switch(direction) { case Direction.N: newY--; break; case Direction.NE: newY--; newX++; break; case Direction.NW: newY--; newX--; break; case Direction.S: newY++; break; case Direction.SE: newY++; newX++; break; case Direction.SW: newY++; newX--; break; case Direction.E: newX++; break; case Direction.W: newX--; break; } if(newX >= 0 && newX < region.getWidth() && newY >= 0 && newY < region.getHeight()) { Terrain tmpTerrain = region.getTerrain(newX, newY); if (TerrainManager.allowsMonsterToPass(tmpTerrain, monster) && quinoa.getMonster(newX, newY) == null) { monster.setPosition(newX, newY); TerrainManager.step(region.getTerrain(newX, newY), newX, newY, region, quinoa); } else { //Do nothing } } else { //out of bounds, but do not inform the player } }
public static void executeItemVerbCommand(Monster monster, MonsterCommand command, Quinoa quinoa) { Item item = monster.inventory.getItem(command.getParameter("itemID")); ItemVerb verb = (ItemVerb)Enum.Parse(typeof(ItemVerb), command.getParameter("verb")); Region region = quinoa.getCurrentRegionHeader().getRegion(); int x = Int32.Parse(command.getParameter("x")); int y = Int32.Parse(command.getParameter("y")); bool removeItem=false; if(item != null) { switch(verb) { case ItemVerb.EAT: foreach(ItemAttribute attribute in item.attributes) { if(attribute.type == ItemAttributeType.NUTRITION) { double nutrition = Double.Parse(attribute.parameter); monster.stats.setCurrentHunger(monster.stats.getCurrentHunger() - nutrition); if(monster.stats.getCurrentHunger() < 0) { monster.stats.setCurrentHunger(0.0); } if(isPlayer(monster)) { quinoa.getMessageManager().addMessage("Ate " + EnumUtil.EnumName<ItemClass>(item.itemClass) + "."); } } if(attribute.type == ItemAttributeType.HEALS) { double points = Double.Parse(attribute.parameter); monster.stats.setCurrentHealth(monster.stats.getCurrentHealth() + points); if(monster.stats.getCurrentHealth() > monster.stats.getMaxHP()) { monster.stats.setCurrentHealth(monster.stats.getMaxHP()); } if(isPlayer(monster)) { if(points >= 0) { quinoa.getMessageManager().addMessage("You feel better."); } else { quinoa.getMessageManager().addMessage("You feel worse."); } } } } removeItem = true; break; case ItemVerb.PLACE: removeItem = MonsterActionManager.place(monster, item, x, y, region, quinoa); break; case ItemVerb.USE: removeItem = use(monster, item, x, y, region, quinoa); break; } if(removeItem) { if(item.stackSize > 1) { item.stackSize = item.stackSize - 1; } else { item.RemoveObject(); } } } else { //Non-item verbs switch(verb) { case ItemVerb.ACTIVATE: MonsterActionManager.activate(monster, x, y, region, quinoa); break; case ItemVerb.TALK: if(isPlayer(monster)) { quinoa.getActions().talk(x, y); quinoa.getActions().showDialog(); } break; case ItemVerb.LOOK: if(isPlayer(monster)) { quinoa.getActions().look(x, y); quinoa.getActions().showDialog(); } break; case ItemVerb.TRADE: if(isPlayer(monster)) { quinoa.getActions().trade(x, y); } break; case ItemVerb.SLEEP: Item terrainItem = region.getItem(x, y); if(terrainItem != null) { foreach(ItemAttribute ia in terrainItem.attributes) { if(ia.type == ItemAttributeType.SLEEPS_FOR) { int hours = Int32.Parse(ia.parameter.Split(new char[]{' '})[0]); monster.setPosition(x, y); monster.sleeping = Quinoa.TICKS_PER_SECOND * 60 * 60 * hours; break; } } } if(TerrainManager.hasParameter(region.getTerrain(x, y), TerrainParameter.HAS_BED)) { int hours = 4; monster.setPosition(x, y); monster.sleeping = Quinoa.TICKS_PER_SECOND * 60 * 60 * hours; } else { if(isPlayer(monster)) { quinoa.getMessageManager().addMessage("You can't sleep there."); } } break; } } }
public static void executeEquipCommand(Monster monster, MonsterCommand command, Quinoa quinoa) { String itemID = command.getParameter("itemID"); Item itemToEquip = monster.inventory.getItem(itemID); if(itemToEquip != null) { //check for a free slot ItemSlot freeSlot = ItemManager.getFreeItemSlot(monster, itemToEquip); if(freeSlot != ItemSlot.NULL) { Item newItem = (Item)itemToEquip.CopyObject(); monster.inventory.removeItem(itemID); monster.inventory.equipItem(newItem, freeSlot); if(isPlayer(monster)) { quinoa.getMessageManager().addMessage("Equiped " + EnumUtil.EnumName<ItemClass>(newItem.itemClass) + "."); } } else { if(isPlayer(monster)) { quinoa.getMessageManager().addMessage("No space to equip that."); } } } }
public static void executeDropCommand(Monster monster, MonsterCommand command, Quinoa quinoa) { String itemID = command.getParameter("itemID"); Item itemToDrop = monster.inventory.getItem(itemID); if(itemToDrop != null) { Item newItem = (Item)itemToDrop.CopyObject(); newItem.itemState = ItemState.GROUND; newItem.setPosition(monster.x, monster.y); quinoa.getCurrentRegionHeader().getRegion().getItems().Add(newItem); monster.inventory.removeItem(itemID); monster.inventory.removedExpiredItems(); if(isPlayer(monster)) { quinoa.getMessageManager().addMessage("Dropped " + itemToDrop.itemClass + "."); } } }
public static void executeAttackCommand(Monster monster, MonsterCommand command, Quinoa quinoa) { Monster monsterToAttack = quinoa.getMonsterByID(command.getParameter("monsterID")); if(monsterToAttack != null) { if(quinoa.monsterIsAdjacent(monster.x, monster.y, monsterToAttack.ID)) { //Do a combat attack MonsterActionManager.combat(monster, monsterToAttack, quinoa); //Check for removal if not player //Also check for kill if(!monsterToAttack.ID.Equals(MonsterActionManager.PLAYER_ID) && !(monsterToAttack.stats.getCurrentHealth() > 1)) { monsterToAttack.RemoveObject(); monsterKilled(monster, monsterToAttack, quinoa); } } else { //Attack misses automatically if(monster.ID.Equals(MonsterActionManager.PLAYER_ID)) { quinoa.getMessageManager().addMessage("You miss the " + EnumUtil.EnumName<MonsterCode>(monsterToAttack.monsterCode) + "."); } } } else { //Monster cannot be found if(monster.ID.Equals(MonsterActionManager.PLAYER_ID)) { quinoa.getMessageManager().addMessage("You swing at nothing."); } } }