public void RemoveEquipment(InventoryItems item, bool willEquip = false) { var equip = equipment[item.GetType().ToString()]; if (equip == null) { return; } if (item.GetType() == typeof(Lightsource)) { Lightsource temp = equip.item as Lightsource; CharacterStats.sightBonusFromItems -= temp.lightRadius; } else if (item.GetType() == typeof(Weapon)) { References.rf.playerMovement.meleeWeapon = null; AnimationClip idleClip = animations.DefaultIdleClip("One_handedMelee"); AnimationClip walkClip = animations.DefaultWalkClip("One_handedMelee"); overrider["BaseIdle"] = idleClip; overrider["BaseWalk"] = walkClip; anim.runtimeAnimatorController = overrider; anim.SetLayerWeight(1, 1f); } else { Armor armor = item as Armor; if (item.GetType() == typeof(Chestgear)) { foreach (var obj in chestgearEquipment) { obj.Value.sprite = null; } } Info.AddDefenses(armor, true); } if (equip.obj != null) { Destroy(equip.obj); } ApplyGearEffects(equip.item, true); if (!willEquip) { CalculateStats(); StartCoroutine("UpdateInventoryGear"); } equip.item = null; }
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"); }