public List <Equipped> GetAllEquipped() { List <Equipped> equippedItems = new List <Equipped>(); SqlDataReader reader = null; using (SqlConnection _conn = new SqlConnection(connectionString)) { _conn.Open(); SqlCommand cmd = new SqlCommand("GetAllEquipped", _conn); cmd.CommandType = CommandType.StoredProcedure; reader = cmd.ExecuteReader(); while (reader.Read()) { int id = Convert.ToInt32(reader["EquippedID"]); int weaponID = Convert.ToInt32(reader["Weapon"]); int helmetID = Convert.ToInt32(reader["Helmet"]); int bodyID = Convert.ToInt32(reader["Body"]); int legsID = Convert.ToInt32(reader["Legs"]); int feetID = Convert.ToInt32(reader["Feet"]); Equipped equipped = new Equipped(id, weaponID, helmetID, bodyID, legsID, feetID); equippedItems.Add(equipped); } } return(equippedItems); }
/// <summary> /// Print the object's XML to the XmlWriter. /// </summary> /// <param name="objWriter">XmlTextWriter to write with.</param> /// <param name="objCulture">Culture in which to print.</param> /// <param name="strLanguageToPrint">Language in which to print</param> public void Print(XmlTextWriter objWriter, CultureInfo objCulture, string strLanguageToPrint) { objWriter.WriteStartElement("armormod"); objWriter.WriteElementString("name", DisplayNameShort(strLanguageToPrint)); objWriter.WriteElementString("fullname", DisplayName(strLanguageToPrint)); objWriter.WriteElementString("name_english", Name); objWriter.WriteElementString("category", DisplayCategory(strLanguageToPrint)); objWriter.WriteElementString("category_english", Category); objWriter.WriteElementString("armor", Armor.ToString(objCulture)); objWriter.WriteElementString("maxrating", MaximumRating.ToString(objCulture)); objWriter.WriteElementString("rating", Rating.ToString(objCulture)); objWriter.WriteElementString("avail", TotalAvail(objCulture, strLanguageToPrint)); objWriter.WriteElementString("cost", TotalCost.ToString(_objCharacter.Options.NuyenFormat, objCulture)); objWriter.WriteElementString("owncost", OwnCost.ToString(_objCharacter.Options.NuyenFormat, objCulture)); objWriter.WriteElementString("source", CommonFunctions.LanguageBookShort(Source, strLanguageToPrint)); objWriter.WriteElementString("page", DisplayPage(strLanguageToPrint)); objWriter.WriteElementString("included", IncludedInArmor.ToString()); objWriter.WriteElementString("equipped", Equipped.ToString()); objWriter.WriteElementString("wirelesson", WirelessOn.ToString()); objWriter.WriteStartElement("gears"); foreach (Gear objGear in Gear) { objGear.Print(objWriter, objCulture, strLanguageToPrint); } objWriter.WriteEndElement(); objWriter.WriteElementString("extra", LanguageManager.TranslateExtra(_strExtra, strLanguageToPrint)); if (_objCharacter.Options.PrintNotes) { objWriter.WriteElementString("notes", Notes); } objWriter.WriteEndElement(); }
public void Equip(Relic relic, RelicSlot slot) { var previousSlot = FindContainingSlot(relic); if (previousSlot != null) { if (!slot.IsEmpty) { var temp = previousSlot.Relic; previousSlot.Equip(slot.Relic); slot.Equip(temp); return; } Unequip(relic); } if (!slot.IsEmpty) { Unequip(slot.Relic); } relic.Owner = gameObject; relic.Equip(); slot.Equip(relic); Equipped?.Invoke(this, relic); }
private void UnequipItem(InventoryItemInstance item, bool postMessage) { if (!item.Equipped) { throw new InvalidOperationException(); } EquipSlot slot = InventoryModel.GetItemSlot(item.ItemModel); if (slot != EquipSlot.None) { Equipped.Remove(slot); } //allow continuing even if it's not actually equippable, for fixing bugs //magazine logic if (item.ItemModel is RangedWeaponItemModel rwim && rwim.UseMagazine) { Inventory.AddItem(rwim.AType.ToString(), AmmoInMagazine[slot]); AmmoInMagazine[slot] = 0; } item.Equipped = false; UpdateStats(); if (postMessage) { QdmsMessageBus.Instance.PushBroadcast(new QdmsKeyValueMessage("RpgChangeWeapon", "Slot", slot)); } }
// When game started, assign the image to the UIItem, find the selected item public void Awake() { spriteImage = GetComponent <Image>(); UpdateItem(null); selectedItem = GameObject.Find("SelectedItem").GetComponent <UIItem>(); tooltip = GameObject.Find("Tooltip").GetComponent <Tooltip>(); equipped = GameObject.Find("Equipped Master Panel").GetComponent <Equipped>(); click = GameObject.Find("Click Sound").GetComponent <AudioSource>(); player = GameObject.Find("Player").GetComponent <PlayerMovement>(); }
public InventoryItemInstance UnequipItem(EquipSlot slot) { if (slot != EquipSlot.None && Equipped.TryGetValue(slot, out var item) && item != null) { UnequipItem(item); return(item); } return(null); }
// Use this for initialization void Start () { equipState = Equipped.Primary; primaryWeapon = gameObject.AddComponent<Weapon>(); Animator anim = GetComponent<Animator> (); if (anim.runtimeAnimatorController.name.Contains ("elf")) { primaryWeapon.SetRange (10); } primaryWeapon.projectilePrefab = prefab; }
/// <summary> /// Create a new player object. /// </summary> /// <param name="game">The game instance.</param> internal Player(GameInstance game) { Id = idNext++; GameInstance = game; Board = new Board(); Deck = new Deck(); DiscardPile = new DiscardPile(); Equipped = new Equipped(); FaceUp = new FaceUp(); Graveyard = new Graveyard(); Hand = new Hand(); }
private void RecalculateStats() { //copy base stats DerivedStats = new StatsSet(BaseStats); //apply conditions foreach (Condition c in Conditions) { c.Apply(BaseStats, DerivedStats); } //apply equipment bonuses (armor basically) if (Equipped.ContainsKey(EquipSlot.Body)) { ArmorItemModel aim = Equipped[EquipSlot.Body].ItemModel as ArmorItemModel; if (aim != null) { foreach (var key in BaseStats.DamageResistance.Keys) { if (aim.DamageResistance.ContainsKey((DamageType)key)) { DerivedStats.DamageResistance[key] = BaseStats.DamageResistance[key] + aim.DamageResistance[(DamageType)key]; } if (aim.DamageThreshold.ContainsKey((DamageType)key)) { DerivedStats.DamageThreshold[key] = BaseStats.DamageThreshold[key] + aim.DamageThreshold[(DamageType)key]; } } } else { Debug.LogWarning("Player has non-armor item in armor slot!"); } } //apply derived skills if (GameParams.UseDerivedSkills) { RpgValues.SkillsFromStats(BaseStats, DerivedStats); } //recalculate max health and energy DerivedStats.MaxHealth = RpgValues.MaxHealth(this); DerivedStats.MaxEnergy = RpgValues.MaxEnergy(this); //apply endurance from difficulty float endurance = ConfigState.Instance.GetGameplayConfig().Difficulty.PlayerEndurance; DerivedStats.MaxHealth *= endurance; DerivedStats.MaxEnergy *= endurance; }
public void Equip() { if (IsEmpty) { return; } Owner.GetComponent <BehavioursComponent>().Apply(Behaviour, Owner); Experience.LevelUp += OnLevelUp; OnLevelUp(Experience); IsEquipped = true; Equipped?.Invoke(this); }
public void DieForReal() { Status = GameStatus.Sitting; HitPoints = 1; var deathRoom = RoomHelper.GetPlayerRoom(Location); deathRoom.RemovePlayer(this); // create corpse var corpse = Server.Current.Database.Get <Template>("corpse"); var dupedCorpse = Mapper.Map <PlayerItem>(corpse); var corpseName = string.Format("The corpse of {0}", Forename); dupedCorpse.AllowedToLoot = Key; // this should be the only place this is used dupedCorpse.Name = corpseName; dupedCorpse.Description = corpseName; dupedCorpse.Keywords = new [] { "corpse", Forename }; dupedCorpse.WearLocation = Wearlocation.Corpse; Console.WriteLine("NEW CORPSE: {0}", dupedCorpse.Key); deathRoom.CorpseQueue[dupedCorpse.Key] = DateTime.Now.AddMilliseconds(Server.CorpseDecayTime); // copy player items to corpse foreach (var item in Inventory .Select(x => new { Key = x.Key, Value = x.Value }) .Union(Equipped.Values.Select(x => new { Key = x.Key, Value = x.Name }) .ToArray())) { dupedCorpse.ContainedItems.Add(item.Key, item.Value); } // clear inventory/equipped Inventory.Clear(); Equipped.Clear(); // cache, don't save Server.Current.Database.Put(dupedCorpse); deathRoom.AddItem(dupedCorpse); var room = RoomHelper.GetPlayerRoom(RespawnRoom); Location = RespawnRoom; room.AddPlayer(this); Server.Current.Database.Save(this); }
public void CycleEquipment() { if (currEquipped == Equipped.Shield) { shield.Unequip(); currEquipped = Equipped.Turret; turret.Equip(); } else if (currEquipped == Equipped.Turret) { turret.Unequip(); currEquipped = Equipped.Shield; shield.Equip(); } else if (currEquipped == Equipped.Empty) { currEquipped = Equipped.Shield; shield.Equip(); } }
public void Defeated(PlayerClass winner) { var amount = 0; if (!IsMonster) { amount = (int)Mathf.Floor((30f / 100f) * Gold); if (amount == 0) { amount = 1; } Gold -= amount; } else { amount = Gold; } if (Gold < 0) { Gold = 0; } if (winner != null) { var bonus = Mathf.FloorToInt(amount * Equipped.Where(a => a.Type == CardClass.CardType.GOLD).Sum(a => a.Value) / 100f); if (IsMonster) { winner.Gold += amount + (GameController.Turn * 6) + bonus; winner.ATK += Mathf.Ceil((30f / 100f) * (float)ATK); } else { winner.Gold += amount + bonus; } } }
// Check if an item is in the inventory. public static bool IsEquipped(string item) { if (!ItemDatabase.Exists(item)) { return(true); // Assume true, TODO: warning handled elsewhere } string ItemSlot = ItemDatabase.GetSlot(item); if (concat_slots.Contains(ItemSlot)) { foreach (string Equipped in Slot[ItemSlot]) { if (Equipped.ToUpper() == item.ToUpper()) { return(true); } } return(false); } else { return(Regex.IsMatch(Slot[ItemSlot], item, RegexOptions.IgnoreCase)); } }
public ISavable Equip(int playerId, Equipment equipment, int slot) { Equipped equipped = GetRelationWithItem(playerId, equipment.Type).GetValueOrDefault(slot); if (equipped == null) { equipped = new Equipped { ItemId = equipment.Id, PlayerId = playerId, Slot = slot, EquipmentType = equipment.Type }; context.Add(equipped); } else { mediator.GetHandler <PlayerInventory>().AddItem(playerId, new ItemDescriptor(equipped.Item.Id, equipped.Item.Name, 1)); equipped.ItemId = equipment.Id; } return(context); }
// Unequip a worn item public void Unequip(Item thing) { Equipped.Remove(thing); }
/// <summary> /// Resets the NPC's state back to the initial values, and re-creates the inventory and equipped items they /// will spawn with. /// </summary> void LoadSpawnState() { // All items remaining in the inventory or equipment should NOT be referenced! // Items that were dropped should have been removed when dropping Inventory.RemoveAll(true); Equipped.RemoveAll(true); // Grab the respawn items from the template var templateID = CharacterTemplateID; if (!templateID.HasValue) { return; } var template = CharacterTemplateManager[templateID.Value]; if (template == null) { return; } // Create the inventory items var spawnInventory = template.Inventory; if (spawnInventory != null) { foreach (var inventoryItem in spawnInventory) { var item = inventoryItem.CreateInstance(); if (item == null) { continue; } Inventory.Add(item); } } // Create the equipped items var spawnEquipment = template.Equipment; if (spawnEquipment != null) { foreach (var equippedItem in spawnEquipment) { var item = equippedItem.CreateInstance(); if (item == null) { continue; } if (!Equipped.Equip(item)) { item.Destroy(); } } } // Reset the known skills var spawnKnownSkills = template.KnownSkills; KnownSkills.SetValues(spawnKnownSkills); }
// Equip a wearable item public void Equip(Item thing) { Equipped.Add(thing); }
/// <summary> /// Get item information. /// </summary> /// <returns>Item stats and information.</returns> public virtual string[] GetInfo() { string[] info = { Equipped.ToString(), Name, Desc, Strength.ToString(), Dex.ToString(), Int.ToString(), Def.ToString(), Hp.ToString() }; return(info); }
/// <summary> /// When overridden in the derived class, implements the Character being killed. This /// doesn't actually care how the Character was killed, it just takes the appropriate /// actions to kill them. /// </summary> public override void Kill() { base.Kill(); if (!IsAlive) { const string errmsg = "Attempted to kill dead NPC `{0}`."; if (log.IsErrorEnabled) { log.ErrorFormat(errmsg, this); } Debug.Fail(string.Format(errmsg, this)); return; } // Drop items if (Map == null) { const string errmsg = "Attempted to kill NPC `{0}` with a null map."; if (log.IsErrorEnabled) { log.ErrorFormat(errmsg, this); } Debug.Fail(string.Format(errmsg, this)); } else { EventCounterManager.Map.Increment(Map.ID, MapEventCounterType.NPCKilled); foreach (var item in Inventory) { var template = item.Value.ItemTemplateID; if (template.HasValue) { EventCounterManager.ItemTemplate.Increment(template.Value, ItemTemplateEventCounterType.DroppedAsLoot, item.Value.Amount); } DropItem(item.Value); } Inventory.RemoveAll(false); } // Remove equipment Equipped.RemoveAll(true); // Check to respawn if (WillRespawn) { // Start the respawn sequence IsAlive = false; RespawnTime = (TickCount)(GetTime() + (RespawnSecs * 1000)); LoadSpawnState(); Teleport(null, Vector2.Zero); World.AddToRespawn(this); } else { // No respawning, so just dispose Debug.Assert(!IsDisposed); DelayedDispose(); } }
public void AddEquipment(GameObject obj, InventoryItems item) { var equip = equipment[item.GetType().ToString()]; if (equip.item != null && equip.item.Equals(item)) { return; } if (equip.item != null) { RemoveEquipment(equip.item, true); } equip.item = item; if (item.GetType() != typeof(Chestgear)) { var srs = obj.GetComponentsInChildren <SpriteRenderer>(); foreach (var sr in srs) { sr.material = item.material == null ? defaultMat : item.material; } if (equip.obj != null) { Destroy(equip.obj); } equip.obj = Instantiate(obj); if (equip.item.modifiedMat != null) { equip.obj.GetComponent <SpriteRenderer>().material = equip.item.modifiedMat; } equip.obj.transform.SetParent(equip.trans, false); } if (equip.item.GetType() == typeof(Lightsource)) { Lightsource temp = equip.item as Lightsource; Debug.Log(equip.obj.transform.rotation); Weapon wep = CharacterStats.characterEquipment.weapon; if (wep != null) { if (wep.hands == Hands.One_handed) { equip.obj.transform.SetParent(oneHandedLightSource, false); } else { equip.obj.transform.SetParent(twoHandedLightSource, false); } } else { equip.obj.transform.SetParent(oneHandedLightSource); } CharacterStats.sightBonusFromItems += temp.lightRadius; } else if (equip.item.GetType() == typeof(Weapon)) { Weapon temp = equip.item as Weapon; string defWep = temp.weaponType == WeaponType.Melee ? "Melee" : "Ranged"; Equipped ls = equipment["Lightsource"]; if (ls.obj != null) { if (temp.hands == Hands.One_handed) { ls.obj.transform.SetParent(oneHandedLightSource, false); } else { ls.obj.transform.SetParent(twoHandedLightSource, false); } } AnimationClip attackClip = temp.attackAnimation == null?animations.DefaultAttackClip(temp.hands + defWep) : temp.attackAnimation; AnimationClip idleClip = animations.DefaultIdleClip(temp.hands + defWep); AnimationClip walkClip = animations.DefaultWalkClip(temp.hands + defWep); overrider["BaseAttack"] = attackClip; overrider["BaseIdle"] = idleClip; overrider["BaseWalk"] = walkClip; anim.runtimeAnimatorController = overrider; anim.SetLayerWeight(1, 1f); ParticleSystem trail = equip.obj.GetComponentInChildren <ParticleSystem>(); if (trail != null) { References.rf.playerMovement.weaponTrailRenderer = trail; if (temp.weaponType == WeaponType.Melee || temp.weaponType == WeaponType.Flamethrower) { trail.Stop(); } } if (temp.weaponType == WeaponType.Melee) { References.rf.playerMovement.meleeWeapon = equip.obj.GetComponent <MeleeWeaponHit>(); } } else { Armor armor = equip.item as Armor; if (equip.item.GetType() == typeof(Chestgear)) { foreach (Transform trans in obj.transform) { chestgearEquipment[trans.name].sprite = trans.GetComponent <SpriteRenderer>().sprite; chestgearEquipment[trans.name].material = item.material == null ? defaultMat : item.material; } } Info.AddDefenses(armor); } ApplyGearEffects(equip.item, false); CalculateStats(); StartCoroutine("UpdateInventoryGear"); }
/// <summary> /// Tries to set a given <paramref name="slot"/> to a new <paramref name="item"/>. /// </summary> /// <param name="slot">Slot to set the item in.</param> /// <param name="item">Item to set the slot to.</param> /// <param name="checkIfCanEquip">If true, the specified <paramref name="item"/> will /// be checked if it can be euqipped with <see cref="CanEquip"/>. If false, this additional /// check will be completely bypassed.</param> /// <returns>True if the <paramref name="item"/> was successfully added to the specified /// <paramref name="slot"/>, else false. When false, it is guarenteed the equipment will /// not have been modified.</returns> protected bool TrySetSlot(EquipmentSlot slot, T item, bool checkIfCanEquip = true) { // Check for a valid EquipmentSlot if (!EnumHelper <EquipmentSlot> .IsDefined(slot)) { const string errmsg = "Invalid EquipmentSlot `{0}` specified."; if (log.IsErrorEnabled) { log.ErrorFormat(errmsg, slot); } Debug.Fail(string.Format(errmsg, slot)); return(false); } // Get the array index for the slot var index = slot.GetValue(); // If the slot is equal to the value we are trying to set it, we never want // to do anything extra, so just abort var currentItem = this[index]; if (currentItem == item) { return(false); } if (item != null) { // Add item // Ensure the item can be equipped if (checkIfCanEquip) { if (!CanEquip(item)) { return(false); } } // If the slot is already in use, remove the item, aborting if removal failed if (currentItem != null) { if (!RemoveAt(slot)) { return(false); } } // Attach the listener for the OnDispose event item.Disposed -= ItemDisposeHandler; item.Disposed += ItemDisposeHandler; // Set the item into the slot _equipped[index] = item; OnEquipped(item, slot); if (Equipped != null) { Equipped.Raise(this, new EquippedEventArgs <T>(item, slot)); } } else { // Remove item (set to null) // Check if the item can be removed if (!CanRemove(slot)) { return(false); } var oldItem = _equipped[index]; // Remove the listener for the OnDispose event oldItem.Disposed -= ItemDisposeHandler; // Remove the item _equipped[index] = null; OnUnequipped(oldItem, slot); if (Unequipped != null) { Unequipped.Raise(this, new EquippedEventArgs <T>(oldItem, slot)); } } // Slot setting was successful (since we always aborted early with false if it wasn't) return(true); }
public inventory(int _InventorySize) { InventorySize = _InventorySize; InventoryData = new List <GameObject>(InventorySize); EquipData = new Equipped(); }
public void UpdateInventoryCache() { using (new PerformanceLogger("UpdateCachedInventoryData")) { Clear(); if (!ZetaDia.IsInGame || ZetaDia.Me == null || !ZetaDia.Me.IsValid || ZetaDia.CPlayer == null || !ZetaDia.CPlayer.IsValid) { return; } //var itemList = ZetaDia.Actors.GetActorsOfType<ACDItem>(); // Using backpack only for now, as grabbing all ACDItems is just slow and we don't have a use for them yet. //var itemList = ZetaDia.Me.Inventory.Backpack; //var inventory = ZetaDia.Me.Inventory; //Equipped = inventory.Equipped.ToList(); //EquippedIds = new HashSet<int>(Equipped.Select(i => i.ActorSNO)); //Backpack = inventory.Backpack.ToList(); //Stash = inventory.StashItems.ToList(); KanaisCubeIds = new HashSet <int>(ZetaDia.CPlayer.KanaisPowersAssignedActorSnoIds); // this turns out to be much faster than accessing ZetaDia.Me.Inventory foreach (var item in ZetaDia.Actors.GetActorsOfType <ACDItem>().ToList()) { if (!item.IsValid) { continue; } switch (item.InventorySlot) { case InventorySlot.BackpackItems: Backpack.Add(item); break; //case InventorySlot.SharedStash: // Stash.Add(item); // break; case InventorySlot.Bracers: case InventorySlot.Feet: case InventorySlot.Hands: case InventorySlot.Head: case InventorySlot.Waist: case InventorySlot.Shoulders: case InventorySlot.Torso: case InventorySlot.LeftFinger: case InventorySlot.RightFinger: case InventorySlot.RightHand: case InventorySlot.LeftHand: case InventorySlot.Legs: case InventorySlot.Neck: case InventorySlot.Socket: Equipped.Add(item); EquippedIds.Add(item.ActorSNO); break; //case InventorySlot.Buyback: //case InventorySlot.None: default: if ((int)item.InventorySlot == 19) { Equipped.Add(item); EquippedIds.Add(item.ActorSNO); } //Other.Add(item); break; } } //IsGroundItemOverload = (Ground.Count > 50); //Logger.Log(TrinityLogLevel.Debug, LogCategory.CacheManagement, // "Refreshed Inventory: Backpack={0} Stash={1} Equipped={2} Ground={3}", // Backpack.Count, // Stash.Count, // Equipped.Count, // Ground.Count); } }
public void EquipItem(InventoryItemInstance item, EquipSlot?slotOverride) { if (item.Equipped) { throw new InvalidOperationException(); } EquipSlot slot = slotOverride ?? InventoryModel.GetItemSlot(item.ItemModel); if (slot == EquipSlot.None) { throw new InvalidOperationException(); } //unequip what was in the slot if (IsEquipped(slot)) { UnequipItem(Equipped[slot], false); } //if it's a two-handed weapon, also unequip the other slot if (item.ItemModel is WeaponItemModel && item.ItemModel.CheckFlag("TwoHanded") && Equipped.ContainsKey(slot == EquipSlot.LeftWeapon ? EquipSlot.RightWeapon : EquipSlot.LeftWeapon)) { UnequipItem(Equipped[slot == EquipSlot.LeftWeapon ? EquipSlot.RightWeapon : EquipSlot.LeftWeapon], false); } Equipped[slot] = item; //magazine logic if (item.ItemModel is RangedWeaponItemModel rwim && rwim.UseMagazine) { //var rwim = (RangedWeaponItemModel)item.ItemModel; AmmoInMagazine[slot] = Math.Min(rwim.MagazineSize, Inventory.CountItem(rwim.AType.ToString())); Inventory.RemoveItem(rwim.AType.ToString(), AmmoInMagazine[slot]); } item.Equipped = true; UpdateStats(); QdmsMessageBus.Instance.PushBroadcast(new QdmsKeyValueMessage("RpgChangeWeapon", "Slot", slot)); }
public bool IsEquipped(EquipSlot slot) { return(Equipped.ContainsKey(slot) && Equipped[slot] != null); }
public void Equip(Relic relic) { Relic = relic; Equipped?.Invoke(this, relic); }