public bool UnequipFromSlot(EquipSlotType slot) { int slotNum = (int)slot; if (equipList[slotNum].equip == null) { return(false); } Equipment equip = equipList[slotNum].equip; equipList[slotNum].equip = null; equip.equippedToHero = null; if (equipList[slotNum].isDisabled) { equipList[slotNum].isDisabled = false; } else { RemoveEquipmentBonuses(equip.GetAllAffixes()); } UpdateActorData(); return(true); }
private (bool status, int val) IsValidIdx(EquipSlotType slot) { var idx = (int)slot; if (0 > idx || idx >= EquipmentMaxSize) { return(false, -1); } return(true, idx); }
public void ItemEquip(Item item, EquipSlotType equipSlot) { if (item == null) { hero.UnequipFromSlot(equipSlot); } else { hero.EquipToSlot(item as Equipment, equipSlot); } equipmentPage.UpdateWindow(); }
// TODO: skeleton mapping data public override bool Equals(object other) { //return base.Equals(other); if (other != null && other.GetType() == typeof(EquipSlotType)) { EquipSlotType otherEquip = other as EquipSlotType; // This seems to be working. return(GetInstanceID() == otherEquip.GetInstanceID()); // if ids are the same, then they are the same object } return(false); // not of same object type, so can't be same object }
public static Equipment CreateRandomEquipment_EvenSlotWeight(int ilvl, GroupType?group = null, float baseLevelSkew = 1f) { EquipSlotType slot = (EquipSlotType)UnityEngine.Random.Range(0, 9); if (slot == EquipSlotType.RING_SLOT_1) { slot = EquipSlotType.RING; } Equipment equip = CreateEquipmentFromBase(ResourceManager.Instance.GetRandomEquipmentBase(ilvl, group, slot, baseLevelSkew), ilvl); return(equip); }
public void Equip(Item i) { //Get item index int index = monster.inventory.GetIndexOf(i); if (index == -1) { Debug.LogError("Something has gone very wrong. An item thinks it was equipped, but it's monster did not hold it.", this); return; } //Get equipment index EquipableItem e = i.equipable; EquipSlotType slot = e.primarySlot; for (int c = 0; c < equipmentSlots.Count; c++) { if (equipmentSlots[c].type.Contains(slot) && !equipmentSlots[c].active) { Equip(index, c); return; } } }
public EquipSlotNameType?FirstFreeSlotOfType(EquipSlotType equipSlotType, bool replace = false) { int numSlots = Enum.GetNames(typeof(EquipSlotNameType)).Length; EquipSlotNameType?freeSlot = null; for (int i = 0; i < numSlots; ++i) { if (_equipSlotTypes[i] != equipSlotType) { continue; } if (replace && freeSlot == null) { freeSlot = (EquipSlotNameType)i; } if (_equippedItems[i] == null) { freeSlot = (EquipSlotNameType)i; break; } } return(freeSlot); }
public Equipment GetEquipmentInSlot(EquipSlotType slot) { return(equipList[(int)slot].equip); }
public HashSet <GroupType> GetEquipmentGroupTypes(EquipSlotType equipSlot) { return(GetEquipmentGroupTypes(GetEquipmentInSlot(equipSlot))); }
public Item( string name, string description ) { this.name = name; this.equip_slot = EquipSlotType.NONE; this.description = description; }
public Item( Dictionary<string, Object> d ) { String slot; name = ((string)d["name"]); //.Replace( '_', ' ' ); description = (string)d["description"]; icon = (int)((Int64)d["icon"]); price = (int)((Int64)d["price"]); use_battle = (int)((Int64)d["use_battle"]) > 0; use_menu = (int)((Int64)d["use_menu"]) > 0; func_targetting = (string)d["func_targetting"]; func_effect = (string)d["func_effect"]; slot = (string)d["equip_slot"]; if (String.IsNullOrEmpty(slot)) equip_slot = EquipSlotType.NONE; else { try { equip_slot = (EquipSlotType)Enum.Parse(typeof(EquipSlotType), (string)d["equip_slot"], true); } catch (ArgumentException) { // slot is defined, but the name is illegal! equip_slot = EquipSlotType.NONE; } } equip_modcode = (string)d["equip_modcode"]; equip_stats = _statsHelper( equip_modcode ); List<Object> equippable = (List<Object>)d["equip_by"]; List<Klass> equip_klasses = new List<Klass>(); foreach( string equip_klass in equippable ) { if( equip_klass != "" ) { equip_klasses.Add( Klass.get(equip_klass) ); } } if( equip_klasses.Count > 0 ) { equip_classes = equip_klasses.ToArray(); } if( equip_classes != null ) { type = ItemType.Equipment; _EquipmentFinalizer( d ); } else if( price == 0 ) { type = ItemType.Key; } else { type = ItemType.Consumable; } }
//Confirms the existence of enough slots to attach this item public bool CanEquip(int itemIndex, int EquipIndex) { //Setup vars List <int> neededSlots = new List <int>(); //Get item ItemStack item = inventory[itemIndex]; if (item == null) { Debug.LogError($"Can't attach null item at {itemIndex}"); return(false); } EquipableItem equip = item.held[0].equipable; EquipSlotType primary = equip.primarySlot; //Confirm that, if item is equipped already, it could be moved. if (equip.isEquipped && !equip.removable) { return(false); } { //Main slot checking. Done seperately, caused we can't reroute this one. EquipmentSlot main = equipmentSlots[EquipIndex]; if (!main.type.Contains(primary)) { //We can't equp this to that. return(false); } //Check for main slot cursed //This check is probably unecessary, but I don't think it hurts, so I'm leaving it. if (main.active) { if (!main.removable) { //TODO: Console message about why that's not allowed, and you should feel bad return(false); } } neededSlots.Add(EquipIndex); } { //Second slot checking. If one of these fails, we keep moving down the list until we get one that we like. Having none kills the check. foreach (EquipSlotType t in equip.secondarySlots) { bool succeeded = false; //See if there is a free spot that is not already in the list for (int i = 0; i < equipmentSlots.Count; i++) { EquipmentSlot slot = equipmentSlots[i]; if (slot.removable && slot.type.Contains(t) && !neededSlots.Contains(i)) { //Found a match! neededSlots.Add(i); succeeded = true; break; } } if (!succeeded) { //TODO: Console message me! Debug.Log($"You must have your {t} slot avaible to equip a {item.GetName()}"); return(false); } } } return(true); }
public Inventory GetWearableEquipmentSet( Klass klass, EquipSlotType slot ) { Inventory ret = new Inventory(); foreach( ItemSlot sl in this.equipment ) { if( sl.item.equip_slot == slot && sl.item.equip_classes.Contains( klass ) ) { ret.AddItem( sl.item, sl.quant ); } } if( slot != EquipSlotType.RightHand && slot != EquipSlotType.Body ) { // can't unequip from RH or Body slots ret.AddItem( Item.none, 1 ); } return ret; }
public bool EquipToSlot(Equipment equip, EquipSlotType slot) { if (equip.IsEquipped) { return(false); } if (equip.Base.equipSlot == EquipSlotType.RING) { if (slot != EquipSlotType.RING_SLOT_1 && slot != EquipSlotType.RING_SLOT_2) { return(false); } } else if (equip.Base.equipSlot == EquipSlotType.WEAPON) { if (slot == EquipSlotType.OFF_HAND) { Equipment mainWeapon = equipList[(int)EquipSlotType.WEAPON].equip; if (mainWeapon == null) { slot = EquipSlotType.WEAPON; } else if ((mainWeapon.GetGroupTypes().Contains(GroupType.MELEE_WEAPON) && !equip.GetGroupTypes().Contains(GroupType.MELEE_WEAPON)) || (mainWeapon.GetGroupTypes().Contains(GroupType.RANGED_WEAPON) && !equip.GetGroupTypes().Contains(GroupType.RANGED_WEAPON))) { return(false); } } else if (GetEquipmentGroupTypes(equip).Contains(GroupType.SPEAR) && HasSpecialBonus(BonusType.CAN_USE_SPEARS_WITH_SHIELDS) && slot == EquipSlotType.WEAPON) { if (equipList[(int)EquipSlotType.OFF_HAND].equip == null || !equipList[(int)EquipSlotType.OFF_HAND].equip.GetGroupTypes().Contains(GroupType.SHIELD)) { UnequipFromSlot(EquipSlotType.OFF_HAND); } } else if (GetEquipmentGroupTypes(equip).Contains(GroupType.TWO_HANDED_WEAPON) && !HasSpecialBonus(BonusType.TWO_HANDED_WEAPONS_ARE_ONE_HANDED)) { if (slot == EquipSlotType.WEAPON && equipList[(int)EquipSlotType.OFF_HAND].equip != null) { UnequipFromSlot(EquipSlotType.OFF_HAND); } else if (slot == EquipSlotType.OFF_HAND) { slot = EquipSlotType.WEAPON; } } } else if (equip.Base.equipSlot != slot) { return(false); } UpdatesAreDeferred = true; int slotNum = (int)slot; if (equipList[slotNum].equip != null) { UnequipFromSlot(slot); } switch (slot) { case EquipSlotType.HEADGEAR: case EquipSlotType.BODY_ARMOR: case EquipSlotType.BOOTS: case EquipSlotType.GLOVES: case EquipSlotType.BELT: case EquipSlotType.NECKLACE: case EquipSlotType.WEAPON: case EquipSlotType.OFF_HAND: case EquipSlotType.RING_SLOT_1: case EquipSlotType.RING_SLOT_2: equipList[slotNum].equip = equip; break; default: return(false); } equip.equippedToHero = this; ApplyEquipmentBonuses(equip.GetAllAffixes()); UpdatesAreDeferred = false; UpdateActorData(); return(true); }
public EquipmentSlot( EquipSlotType est ) { equipped = null; slotType = est; }
public void RemoveItemFromSlot(EquipSlotType slot, GameObject item) { equips[slot] = null; }
public void AddItemToSlot(EquipSlotType slot, GameObject item) { equips[slot] = item; }
/* * Returns the slots that must be unequipped. The behaviour of this * function is only sensible while CanEquip() of the same info is true. * This function heavily relies on assumptions given by CanEquip, * so MAKE SURE that that one works first */ public List <int> SlotsNeededToEquip(int itemIndex, int EquipIndex) { //Setup vars List <int> neededSlots = new List <int>(); //Get item ItemStack item = inventory[itemIndex]; //Confirm that slot is open and primary EquipableItem equip = item.held[0].equipable; EquipSlotType primary = equip.primarySlot; EquipmentSlot main = equipmentSlots[EquipIndex]; if (main.active) { neededSlots.Add(EquipIndex); } foreach (EquipSlotType t in equip.secondarySlots) { bool succeeded = false; //See if there is a free spot that is not already in the list for (int i = 0; i < equipmentSlots.Count; i++) { EquipmentSlot slot = equipmentSlots[i]; if (!slot.active && slot.type.Contains(t) && !neededSlots.Contains(i)) { //Found a match! neededSlots.Add(i); succeeded = true; break; } } if (succeeded) { break; } //We're here, so we didn't succeed. Now try the same thing, but with slots that we could remove for (int i = 0; i < equipmentSlots.Count; i++) { EquipmentSlot slot = equipmentSlots[i]; if (slot.active && slot.removable && slot.type.Contains(t) && !neededSlots.Contains(i)) { //Found a match! neededSlots.Add(i); succeeded = true; break; } } if (!succeeded) { Debug.LogError("This should not be possible! Needed Slots has failed the assertion that CanEquip should have provided"); return(neededSlots); } } for (int i = neededSlots.Count - 1; i >= 0; i--) { if (!equipmentSlots[neededSlots[i]].active) { neededSlots.RemoveAt(i); } } return(neededSlots); }
public string GetLocalizationText(EquipSlotType equipSlot) { return(GetLocalizationText("slotType." + equipSlot.ToString())); }