private static void RepairItem(IPlayerCharacterData character, CharacterItem repairingItem, System.Action <CharacterItem> onRepaired, out GameMessage.Type gameMessageType) { gameMessageType = GameMessage.Type.CannotRepair; if (!repairingItem.NotEmptySlot()) { // Cannot refine because character item is empty return; } Item equipmentItem = repairingItem.GetEquipmentItem(); if (equipmentItem == null) { // Cannot refine because it's not equipment item return; } ItemRepairPrice repairPrice; if (equipmentItem.CanRepair(character, repairingItem.durability, out repairPrice, out gameMessageType)) { gameMessageType = GameMessage.Type.RepairSuccess; // Repair item repairingItem.durability = equipmentItem.maxDurability; onRepaired.Invoke(repairingItem); // Decrease required gold GameInstance.Singleton.GameplayRule.DecreaseCurrenciesWhenRepairItem(character, repairPrice); } }
public void UpdateData(ICharacterData character) { this.character = character; // Clear slots data foreach (UICharacterItem slot in CacheEquipItemSlots.Values) { slot.Setup(GetEmptyUIData(slot.InventoryType), character, -1); slot.Show(); } if (character == null) { return; } string tempPosition; UICharacterItem tempSlot; IList <CharacterItem> equipItems = character.EquipItems; for (int i = 0; i < equipItems.Count; ++i) { CharacterItem equipItem = equipItems[i]; Item armorItem = equipItem.GetArmorItem(); if (armorItem == null) { continue; } tempPosition = armorItem.EquipPosition; if (CacheEquipItemSlots.TryGetValue(tempPosition, out tempSlot)) { tempSlot.Setup(new CharacterItemTuple(equipItem, equipItem.level, InventoryType.EquipItems), character, i); } } EquipWeapons equipWeapons = character.EquipWeapons; CharacterItem rightHand = equipWeapons.rightHand; CharacterItem leftHand = equipWeapons.leftHand; Item rightHandEquipment = rightHand.GetEquipmentItem(); Item leftHandEquipment = leftHand.GetEquipmentItem(); tempPosition = GameDataConst.EQUIP_POSITION_RIGHT_HAND; if (CacheEquipItemSlots.TryGetValue(tempPosition, out tempSlot)) { if (rightHandEquipment != null) { tempSlot.Setup(new CharacterItemTuple(rightHand, rightHand.level, InventoryType.EquipWeaponRight), character, 0); } } tempPosition = GameDataConst.EQUIP_POSITION_LEFT_HAND; if (CacheEquipItemSlots.TryGetValue(tempPosition, out tempSlot)) { if (leftHandEquipment != null) { tempSlot.Setup(new CharacterItemTuple(leftHand, leftHand.level, InventoryType.EquipWeaponLeft), character, 0); } } }
private CharacterItem DecreaseDurability(CharacterItem characterItem, float decreaseDurability, out bool destroy) { destroy = false; var item = characterItem.GetEquipmentItem(); if (item != null) { if (characterItem.durability - decreaseDurability <= 0 && item.destroyIfBroken) { destroy = true; } characterItem.durability -= decreaseDurability; if (characterItem.durability < 0) { characterItem.durability = 0; } } return(characterItem); }
private static void EnhanceSocketItem(IPlayerCharacterData character, CharacterItem enhancingItem, int enhancerId, System.Action <CharacterItem> onEnhanceSocket, out GameMessage.Type gameMessageType) { gameMessageType = GameMessage.Type.CannotEnhanceSocket; if (!enhancingItem.NotEmptySlot()) { // Cannot enhance socket because character item is empty return; } Item equipmentItem = enhancingItem.GetEquipmentItem(); if (equipmentItem == null) { // Cannot enhance socket because it's not equipment item return; } if (equipmentItem.maxSocket <= 0) { // Cannot enhance socket because equipment has no socket(s) return; } if (enhancingItem.Sockets.Count >= equipmentItem.maxSocket) { // Cannot enhance socket because socket is full return; } Item enhancerItem; if (!GameInstance.Items.TryGetValue(enhancerId, out enhancerItem) || !enhancerItem.IsSocketEnhancer()) { // Cannot enhance socket because enhancer id is invalid return; } if (!character.DecreaseItems(enhancerItem.DataId, 1)) { // Cannot enhance socket because there is no item gameMessageType = GameMessage.Type.NotEnoughSocketEnchaner; return; } enhancingItem.Sockets.Add(enhancerId); onEnhanceSocket.Invoke(enhancingItem); }
public void OnClickSetEnhanceSocketItem() { // Only owning character can refine item if (!IsOwningCharacter()) { return; } UISceneGameplay uiGameplay = UISceneGameplay.Singleton; if (uiGameplay.uiEnhanceSocketItem != null && CharacterItem.GetEquipmentItem() != null) { uiGameplay.uiEnhanceSocketItem.Data = new CharacterItemByIndexTuple(InventoryType, IndexOfData); uiGameplay.uiEnhanceSocketItem.Show(); if (selectionManager != null) { selectionManager.DeselectSelectedUI(); } } }
public void OnClickSetRefineItem() { // Only unequipped equipment can refining if (!IsOwningCharacter() || !string.IsNullOrEmpty(EquipPosition)) { return; } var uiGameplay = UISceneGameplay.Singleton; if (uiGameplay.uiRefineItem != null && CharacterItem.GetEquipmentItem() != null && string.IsNullOrEmpty(EquipPosition)) { uiGameplay.uiRefineItem.Data = indexOfData; uiGameplay.uiRefineItem.Show(); if (selectionManager != null) { selectionManager.DeselectSelectedUI(); } } }
private static void RefineItem(IPlayerCharacterData character, CharacterItem refiningItem, System.Action <CharacterItem> onRefine, System.Action onDestroy, out GameMessage.Type gameMessageType) { gameMessageType = GameMessage.Type.CannotRefine; if (!refiningItem.NotEmptySlot()) { // Cannot refine because character item is empty return; } Item equipmentItem = refiningItem.GetEquipmentItem(); if (equipmentItem == null) { // Cannot refine because it's not equipment item return; } if (!equipmentItem.CanRefine(character, refiningItem.level, out gameMessageType)) { // Cannot refine because of some reasons return; } ItemRefineLevel refineLevel = equipmentItem.itemRefine.levels[refiningItem.level - 1]; if (Random.value <= refineLevel.SuccessRate) { // If success, increase item level gameMessageType = GameMessage.Type.RefineSuccess; ++refiningItem.level; onRefine.Invoke(refiningItem); } else { // Fail gameMessageType = GameMessage.Type.RefineFail; if (refineLevel.RefineFailDestroyItem) { // If condition when fail is it has to be destroyed onDestroy.Invoke(); } else { // If condition when fail is reduce its level refiningItem.level -= refineLevel.RefineFailDecreaseLevels; if (refiningItem.level < 1) { refiningItem.level = 1; } onRefine.Invoke(refiningItem); } } if (refineLevel.RequireItems != null) { // Decrease required items foreach (ItemAmount requireItem in refineLevel.RequireItems) { if (requireItem.item != null && requireItem.amount > 0) { character.DecreaseItems(requireItem.item.DataId, requireItem.amount); } } } // Decrease required gold GameInstance.Singleton.GameplayRule.DecreaseCurrenciesWhenRefineItem(character, refineLevel); }
public static T ValidateCharacterData <T>(this T character) where T : IPlayerCharacterData { GameInstance gameInstance = GameInstance.Singleton; PlayerCharacter database; if (!GameInstance.PlayerCharacters.TryGetValue(character.DataId, out database)) { return(character); } // Validating character attributes short returningStatPoint = 0; HashSet <int> validAttributeIds = new HashSet <int>(); IList <CharacterAttribute> characterAttributes = character.Attributes; for (int i = characterAttributes.Count - 1; i >= 0; --i) { CharacterAttribute characterAttribute = characterAttributes[i]; int attributeDataId = characterAttribute.dataId; // If attribute is invalid if (characterAttribute.GetAttribute() == null || validAttributeIds.Contains(attributeDataId)) { returningStatPoint += characterAttribute.amount; character.Attributes.RemoveAt(i); } else { validAttributeIds.Add(attributeDataId); } } character.StatPoint += returningStatPoint; // Add character's attributes foreach (Attribute attribute in GameInstance.Attributes.Values) { // This attribute is valid, so not have to add it if (validAttributeIds.Contains(attribute.DataId)) { continue; } CharacterAttribute characterAttribute = new CharacterAttribute(); characterAttribute.dataId = attribute.DataId; characterAttribute.amount = 0; character.Attributes.Add(characterAttribute); } // Validating character skills short returningSkillPoint = 0; HashSet <int> validSkillIds = new HashSet <int>(); IList <CharacterSkill> characterSkills = character.Skills; for (int i = characterSkills.Count - 1; i >= 0; --i) { CharacterSkill characterSkill = characterSkills[i]; Skill skill = characterSkill.GetSkill(); // If skill is invalid or this character database does not have skill if (characterSkill.GetSkill() == null || !database.CacheSkillLevels.ContainsKey(skill) || validSkillIds.Contains(skill.DataId)) { returningSkillPoint += characterSkill.level; character.Skills.RemoveAt(i); } else { validSkillIds.Add(skill.DataId); } } character.SkillPoint += returningSkillPoint; // Add character's skills Dictionary <Skill, short> skillLevels = database.CacheSkillLevels; foreach (KeyValuePair <Skill, short> skillLevel in skillLevels) { Skill skill = skillLevel.Key; // This skill is valid, so not have to add it if (validSkillIds.Contains(skill.DataId)) { continue; } CharacterSkill characterSkill = new CharacterSkill(); characterSkill.dataId = skill.DataId; characterSkill.level = skillLevel.Value; character.Skills.Add(characterSkill); } // Validating character equip weapons List <CharacterItem> returningItems = new List <CharacterItem>(); EquipWeapons equipWeapons = character.EquipWeapons; CharacterItem rightHand = equipWeapons.rightHand; CharacterItem leftHand = equipWeapons.leftHand; if (rightHand.GetEquipmentItem() == null) { if (rightHand.NotEmptySlot()) { returningItems.Add(rightHand); } equipWeapons.rightHand = CharacterItem.Empty; } if (leftHand.GetEquipmentItem() == null) { if (leftHand.NotEmptySlot()) { returningItems.Add(leftHand); } equipWeapons.leftHand = CharacterItem.Empty; } // Validating character equip items IList <CharacterItem> equipItems = character.EquipItems; for (int i = equipItems.Count - 1; i >= 0; --i) { CharacterItem equipItem = equipItems[i]; // If equipment is invalid if (equipItem.GetEquipmentItem() == null) { if (equipItem.NotEmptySlot()) { returningItems.Add(equipItem); } character.EquipItems.RemoveAt(i); } } // Return items to non equip items foreach (CharacterItem returningItem in returningItems) { character.NonEquipItems.Add(returningItem); } character.FillEmptySlots(); DevExtUtils.InvokeStaticDevExtMethods(ClassType, "ValidateCharacterData", character); return(character); }