【Unity】RPG制作 その26-武器、防具アイテム実装その3 装備による能力値の変化実装
はじめに、PlayerManager.csで基本能力値と装備反映後の値を保持するDictionaryを宣言します。
クリックで展開
public Dictionary<GeneralEnum.STATUS, int> baseStatusValue = new Dictionary<GeneralEnum.STATUS, int>(); //基本能力値Dictionary。 public Dictionary<GeneralEnum.STATUS, int> afterEquipStatusValue = new Dictionary<GeneralEnum.STATUS, int>(); //ステータスUPと残りターンのDictionary。 public Dictionary<GeneralEnum.ELEMENT, int> baseResistanceOfElementValue = new Dictionary<GeneralEnum.ELEMENT, int>(); //属性耐性の数値(100が通常) 名前変更 public Dictionary<GeneralEnum.ELEMENT, int> afEqResistanceOfElementValue = new Dictionary<GeneralEnum.ELEMENT, int>();//装備反映後の属性耐性値 New Dictionary<GeneralEnum.STATUSCONDITION, int> ResistanceOfStatusValue = new Dictionary<GeneralEnum.STATUSCONDITION, int>(); //状態変化のかかりやすさ(100が通常) Dictionary<GeneralEnum.STATUSCONDITION, int> afEqResistanceOfStatusValue = new Dictionary<GeneralEnum.STATUSCONDITION, int>();//装備反映後の状態変化のかかりやすさの値 New
Dictionaryの初期化関数と装備による能力値の変化反映後の値(3つのDictionary)を計算する関数を作成します。
クリックで展開
public void InitBaseStatusValue()//New { baseStatusValue[GeneralEnum.STATUS.HP] = maxHp; baseStatusValue[GeneralEnum.STATUS.MP] = maxMp; baseStatusValue[GeneralEnum.STATUS.ATK] = at; baseStatusValue[GeneralEnum.STATUS.DEF] = def; baseStatusValue[GeneralEnum.STATUS.AGI] = agi; baseStatusValue[GeneralEnum.STATUS.LUK] = luk; baseStatusValue[GeneralEnum.STATUS.SENCE] = sence; baseStatusValue[GeneralEnum.STATUS.MAGPOW] = magPow; baseStatusValue[GeneralEnum.STATUS.MAGDEF] = magDef; baseStatusValue[GeneralEnum.STATUS.LEARNABI] = learnAbi; baseStatusValue[GeneralEnum.STATUS.TP] = maxTp; baseStatusValue[GeneralEnum.STATUS.HIT] = hitRate; baseStatusValue[GeneralEnum.STATUS.EVASION] = evasionRate; baseStatusValue[GeneralEnum.STATUS.CRITICAL] = criticalRate; } /// <summary> /// 装備反映後の属性値と状態異常のかかりやすさの値を初期化する /// </summary> public void InitAfterEquipDictionary() //New { foreach (GeneralEnum.STATUS value in Enum.GetValues(typeof(GeneralEnum.STATUS))) { if(value != GeneralEnum.STATUS.NONE) { afterEquipStatusValue[value] = baseStatusValue[value]; } } foreach (GeneralEnum.ELEMENT value in Enum.GetValues(typeof(GeneralEnum.ELEMENT))) { afEqResistanceOfElementValue[value] = 100;//100で初期化しておく } foreach (GeneralEnum.STATUSCONDITION value in Enum.GetValues(typeof(GeneralEnum.STATUSCONDITION))) { afEqResistanceOfStatusValue[value] = 100;//100で初期化しておく } } /// <summary> /// 能力の装備反映後の能力値を計算する /// </summary> public void CalcAllAfterEquipStatusValue()//New { foreach (GeneralEnum.STATUS value in Enum.GetValues(typeof(GeneralEnum.STATUS))) { if(value != GeneralEnum.STATUS.NONE) { //装備反映後の値 = 基本値 + 各武器の変化値+各防具の変化値 //武器の変化値の合計を計算する int weaponValue = 0; weaponValue += equipWeapons[GeneralEnum.EQUIP_SLOT.RIGHTHAND].changeStatusValues[value]; weaponValue += equipWeapons[GeneralEnum.EQUIP_SLOT.LEFTHAND].changeStatusValues[value]; //防具の変化値の合計を計算する int armorValue = 0; armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.HEAD].changeStatusValues[value]; armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.BODY].changeStatusValues[value]; armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.WEIST].changeStatusValues[value]; armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.LEG].changeStatusValues[value]; armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.ACCESSORIES1].changeStatusValues[value]; armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.ACCESSORIES2].changeStatusValues[value]; afterEquipStatusValue[value] = baseStatusValue[value] + weaponValue + armorValue; if (afterEquipStatusValue[value] < 1) afterEquipStatusValue[value] = 1;//能力の最低値1 } } } public void CalcAllAfterEquipResiOfElementValue() //New { foreach (GeneralEnum.ELEMENT value in Enum.GetValues(typeof(GeneralEnum.ELEMENT))) { //装備反映後の値 = 基本値 - 各武器の属性耐性値 - 各防具の属性耐性値 //武器の属性耐性変化値の合計を計算する int weaponValue = 0; if (equipWeapons[GeneralEnum.EQUIP_SLOT.RIGHTHAND].resiElement1 == value) weaponValue += equipWeapons[GeneralEnum.EQUIP_SLOT.RIGHTHAND].resiValueOfElement1; if (equipWeapons[GeneralEnum.EQUIP_SLOT.RIGHTHAND].resiElement2 == value) weaponValue += equipWeapons[GeneralEnum.EQUIP_SLOT.RIGHTHAND].resiValueOfElement2; if (equipWeapons[GeneralEnum.EQUIP_SLOT.RIGHTHAND].resiElement3 == value) weaponValue += equipWeapons[GeneralEnum.EQUIP_SLOT.RIGHTHAND].resiValueOfElement3; if (equipWeapons[GeneralEnum.EQUIP_SLOT.LEFTHAND].resiElement1 == value) weaponValue += equipWeapons[GeneralEnum.EQUIP_SLOT.LEFTHAND].resiValueOfElement1; if (equipWeapons[GeneralEnum.EQUIP_SLOT.LEFTHAND].resiElement2 == value) weaponValue += equipWeapons[GeneralEnum.EQUIP_SLOT.LEFTHAND].resiValueOfElement2; if (equipWeapons[GeneralEnum.EQUIP_SLOT.LEFTHAND].resiElement3 == value) weaponValue += equipWeapons[GeneralEnum.EQUIP_SLOT.LEFTHAND].resiValueOfElement3; //防具の属性耐性変化値の合計を計算する int armorValue = 0; if (equipArmors[GeneralEnum.EQUIP_SLOT.HEAD].resiElement1 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.HEAD].resiValueOfElement1; if (equipArmors[GeneralEnum.EQUIP_SLOT.HEAD].resiElement2 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.HEAD].resiValueOfElement2; if (equipArmors[GeneralEnum.EQUIP_SLOT.HEAD].resiElement3 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.HEAD].resiValueOfElement3; if (equipArmors[GeneralEnum.EQUIP_SLOT.BODY].resiElement1 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.BODY].resiValueOfElement1; if (equipArmors[GeneralEnum.EQUIP_SLOT.BODY].resiElement2 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.BODY].resiValueOfElement2; if (equipArmors[GeneralEnum.EQUIP_SLOT.BODY].resiElement3 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.BODY].resiValueOfElement3; if (equipArmors[GeneralEnum.EQUIP_SLOT.WEIST].resiElement1 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.WEIST].resiValueOfElement1; if (equipArmors[GeneralEnum.EQUIP_SLOT.WEIST].resiElement2 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.WEIST].resiValueOfElement2; if (equipArmors[GeneralEnum.EQUIP_SLOT.WEIST].resiElement3 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.WEIST].resiValueOfElement3; if (equipArmors[GeneralEnum.EQUIP_SLOT.LEG].resiElement1 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.LEG].resiValueOfElement1; if (equipArmors[GeneralEnum.EQUIP_SLOT.LEG].resiElement2 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.LEG].resiValueOfElement2; if (equipArmors[GeneralEnum.EQUIP_SLOT.LEG].resiElement3 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.LEG].resiValueOfElement3; if (equipArmors[GeneralEnum.EQUIP_SLOT.ACCESSORIES1].resiElement1 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.ACCESSORIES1].resiValueOfElement1; if (equipArmors[GeneralEnum.EQUIP_SLOT.ACCESSORIES1].resiElement2 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.ACCESSORIES1].resiValueOfElement2; if (equipArmors[GeneralEnum.EQUIP_SLOT.ACCESSORIES1].resiElement3 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.ACCESSORIES1].resiValueOfElement3; if (equipArmors[GeneralEnum.EQUIP_SLOT.ACCESSORIES2].resiElement1 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.ACCESSORIES2].resiValueOfElement1; if (equipArmors[GeneralEnum.EQUIP_SLOT.ACCESSORIES2].resiElement2 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.ACCESSORIES2].resiValueOfElement2; if (equipArmors[GeneralEnum.EQUIP_SLOT.ACCESSORIES2].resiElement3 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.ACCESSORIES2].resiValueOfElement3; afEqResistanceOfElementValue[value] = baseResistanceOfElementValue[value] - weaponValue - armorValue; Mathf.Clamp(afEqResistanceOfElementValue[value],-100,400);//属性耐性値の範囲-100~400にする } } /// <summary> /// 装備反映後の状態変化のかかりやすさの値を計算する /// </summary> public void CalcAllAfterEquipResiOfStatusValue()//New { foreach (GeneralEnum.STATUSCONDITION value in Enum.GetValues(typeof(GeneralEnum.STATUSCONDITION))) { //装備反映後の値 = 基本値 - 各武器の値 - 各防具の値 //武器の変化値の合計を計算する int weaponValue = 0; if (equipWeapons[GeneralEnum.EQUIP_SLOT.RIGHTHAND].resiStatusCondi1 == value) weaponValue += equipWeapons[GeneralEnum.EQUIP_SLOT.RIGHTHAND].resiValueOfCondi1; if (equipWeapons[GeneralEnum.EQUIP_SLOT.RIGHTHAND].resiStatusCondi2 == value) weaponValue += equipWeapons[GeneralEnum.EQUIP_SLOT.RIGHTHAND].resiValueOfCondi2; if (equipWeapons[GeneralEnum.EQUIP_SLOT.RIGHTHAND].resiStatusCondi3 == value) weaponValue += equipWeapons[GeneralEnum.EQUIP_SLOT.RIGHTHAND].resiValueOfCondi3; if (equipWeapons[GeneralEnum.EQUIP_SLOT.LEFTHAND].resiStatusCondi1 == value) weaponValue += equipWeapons[GeneralEnum.EQUIP_SLOT.LEFTHAND].resiValueOfCondi1; if (equipWeapons[GeneralEnum.EQUIP_SLOT.LEFTHAND].resiStatusCondi2 == value) weaponValue += equipWeapons[GeneralEnum.EQUIP_SLOT.LEFTHAND].resiValueOfCondi2; if (equipWeapons[GeneralEnum.EQUIP_SLOT.LEFTHAND].resiStatusCondi3 == value) weaponValue += equipWeapons[GeneralEnum.EQUIP_SLOT.LEFTHAND].resiValueOfCondi3; //防具の属性耐性変化値の合計を計算する int armorValue = 0; if (equipArmors[GeneralEnum.EQUIP_SLOT.HEAD].resiStatusCondi1 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.HEAD].resiValueOfCondi1; if (equipArmors[GeneralEnum.EQUIP_SLOT.HEAD].resiStatusCondi2 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.HEAD].resiValueOfCondi2; if (equipArmors[GeneralEnum.EQUIP_SLOT.HEAD].resiStatusCondi3 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.HEAD].resiValueOfCondi3; if (equipArmors[GeneralEnum.EQUIP_SLOT.BODY].resiStatusCondi1 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.BODY].resiValueOfCondi1; if (equipArmors[GeneralEnum.EQUIP_SLOT.BODY].resiStatusCondi2 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.BODY].resiValueOfCondi2; if (equipArmors[GeneralEnum.EQUIP_SLOT.BODY].resiStatusCondi3 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.BODY].resiValueOfCondi3; if (equipArmors[GeneralEnum.EQUIP_SLOT.WEIST].resiStatusCondi1 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.WEIST].resiValueOfCondi1; if (equipArmors[GeneralEnum.EQUIP_SLOT.WEIST].resiStatusCondi2 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.WEIST].resiValueOfCondi2; if (equipArmors[GeneralEnum.EQUIP_SLOT.WEIST].resiStatusCondi3 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.WEIST].resiValueOfCondi3; if (equipArmors[GeneralEnum.EQUIP_SLOT.LEG].resiStatusCondi1 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.LEG].resiValueOfCondi1; if (equipArmors[GeneralEnum.EQUIP_SLOT.LEG].resiStatusCondi2 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.LEG].resiValueOfCondi2; if (equipArmors[GeneralEnum.EQUIP_SLOT.LEG].resiStatusCondi3 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.LEG].resiValueOfCondi3; if (equipArmors[GeneralEnum.EQUIP_SLOT.ACCESSORIES1].resiStatusCondi1 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.ACCESSORIES1].resiValueOfCondi1; if (equipArmors[GeneralEnum.EQUIP_SLOT.ACCESSORIES1].resiStatusCondi2 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.ACCESSORIES1].resiValueOfCondi2; if (equipArmors[GeneralEnum.EQUIP_SLOT.ACCESSORIES1].resiStatusCondi3 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.ACCESSORIES1].resiValueOfCondi3; if (equipArmors[GeneralEnum.EQUIP_SLOT.ACCESSORIES2].resiStatusCondi1 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.ACCESSORIES2].resiValueOfCondi1; if (equipArmors[GeneralEnum.EQUIP_SLOT.ACCESSORIES2].resiStatusCondi2 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.ACCESSORIES2].resiValueOfCondi2; if (equipArmors[GeneralEnum.EQUIP_SLOT.ACCESSORIES2].resiStatusCondi3 == value) armorValue += equipArmors[GeneralEnum.EQUIP_SLOT.ACCESSORIES2].resiValueOfCondi3; afEqResistanceOfStatusValue[value] = ResistanceOfStatusValue[value] - weaponValue - armorValue; Mathf.Clamp(afEqResistanceOfStatusValue[value], 0, 200);//状態異常のかかりやすさの値は0~200にする } }
それぞれ武器と防具の能力値の変化量の合計を基本値から引いたものを装備反映後の能力値を入れるDictionaryに入れています。
InitBaseStatusValue関数とInitAfterEquipDictionary関数をPlayerManager.csのStart関数で呼び出します。
クリックで展開
void Start() { InitResistanceValueOfElement(); InitResistanceValueOfStatusCondition(); InitStatusCondi(); InitStatusUp(); InitStatusDown(); InitSkillLevel(); InitSkillExp(); InitEquipWeaponsAndArmor(); InitBaseStatusValue();//New InitAfterEquipDictionary();//New //デバッグ用 SkillLevelDic[GeneralEnum.SKILL.Mining] = 4; SkillLevelDic[GeneralEnum.SKILL.Fishing] = 4; }
装備反映後の能力値の計算を行う3つの関数を装備の変更がなされた時に呼び出すようにします。EquipmentUI.csのPushRemoveEquipButton関数、ChangeWeapon関数、ChangeArmor関数のそれぞれ最後の部分に処理を追加します。
クリックで展開
public void PushRemoveEquipButton(PlayerManager playerManager, GeneralEnum.EQUIP_SLOT equipSlot) { //武器と防具両方のEntityの変数を用意する WeaponEntity tempWeapon; ArmorEntity tempArmor; if (equipSlot == GeneralEnum.EQUIP_SLOT.RIGHTHAND || equipSlot == GeneralEnum.EQUIP_SLOT.LEFTHAND)//右手か左手の場合 { //装備している武器もしくは防具を一時変数に入れる if (playerManager.equipWeapons[equipSlot].nowEquip) { tempWeapon = playerManager.equipWeapons[equipSlot]; tempArmor = new ArmorEntity(); } else if (playerManager.equipArmors[equipSlot].nowEquip) { tempWeapon = new WeaponEntity(); tempArmor = playerManager.equipArmors[equipSlot]; } else { tempWeapon = new WeaponEntity(); tempArmor = new ArmorEntity(); } //装備していた武器・防具の装備中フラグをfalseにする tempWeapon.nowEquip = false; tempArmor.nowEquip = false; //装備部位の装備を削除する playerManager.equipWeapons[equipSlot] = new WeaponEntity(); playerManager.equipArmors[equipSlot] = new ArmorEntity(); //リストに装備していた武器もしくは防具を代入する。 if(tempWeapon.isRegistry) WeaponManager.instance.RegiEntity(tempWeapon); if(tempArmor.isRegistry) ArmorManager.instance.RegiEntity(tempArmor); } else//右手左手以外の場合 { //装備していた防具を一時変数に入れる tempArmor = playerManager.equipArmors[equipSlot]; //装備していた防具の装備中フラグをfalseにする tempArmor.nowEquip = false; //装備部位の装備を削除する playerManager.equipArmors[equipSlot] = new ArmorEntity(); //リストに装備していた防具を代入する。 if (tempArmor.isRegistry) ArmorManager.instance.RegiEntity(tempArmor); } //装備反映後の能力値を再計算する playerManager.CalcAllAfterEquipStatusValue();//New playerManager.CalcAllAfterEquipResiOfElementValue();//New playerManager.CalcAllAfterEquipResiOfStatusValue();//New SoundManager.instance.PlaySE(35); } public void ChangeWeapon(GeneralEnum.EQUIP_SLOT equip_slot,WeaponEntity weaponEntity, PlayerManager playerManager, int index) { WeaponData weaponData = WeaponManager.instance.GetWeaponDataFromEntity(weaponEntity); WeaponData nowEquipRWeaponData = WeaponManager.instance.GetWeaponDataFromEntity(playerManager.equipWeapons[GeneralEnum.EQUIP_SLOT.RIGHTHAND]); WeaponData nowEquipLWeaponData = WeaponManager.instance.GetWeaponDataFromEntity(playerManager.equipWeapons[GeneralEnum.EQUIP_SLOT.LEFTHAND]); //武器と防具の一時変数を用意する ArmorEntity tempRHandAEntity; ArmorEntity tempLHandAEntity; WeaponEntity tempREntity; WeaponEntity tempLEntity; //右手からチェック if (playerManager.equipArmors[GeneralEnum.EQUIP_SLOT.RIGHTHAND].nowEquip)//防具装備中なら { tempRHandAEntity = playerManager.equipArmors[GeneralEnum.EQUIP_SLOT.RIGHTHAND]; tempREntity = new WeaponEntity(); } else if (playerManager.equipWeapons[GeneralEnum.EQUIP_SLOT.RIGHTHAND].nowEquip)//武器装備中なら { tempRHandAEntity = new ArmorEntity(); tempREntity = playerManager.equipWeapons[GeneralEnum.EQUIP_SLOT.RIGHTHAND]; } else { tempRHandAEntity = new ArmorEntity(); tempREntity = new WeaponEntity(); } //左手からチェック if (playerManager.equipArmors[GeneralEnum.EQUIP_SLOT.LEFTHAND].nowEquip)//防具装備中なら { tempLHandAEntity = playerManager.equipArmors[GeneralEnum.EQUIP_SLOT.LEFTHAND]; tempLEntity = new WeaponEntity(); } else if (playerManager.equipWeapons[GeneralEnum.EQUIP_SLOT.LEFTHAND].nowEquip)//武器装備中なら { tempLHandAEntity = new ArmorEntity(); tempLEntity = playerManager.equipWeapons[GeneralEnum.EQUIP_SLOT.LEFTHAND]; } else { tempLHandAEntity = new ArmorEntity(); tempLEntity = new WeaponEntity(); } if (weaponData.equipPart == GeneralEnum.EQUIP_SLOT.ONEHAND)//新しく装備する武器が片手用なら { if(tempREntity.equipPart == GeneralEnum.EQUIP_SLOT.BOTHHANDS || tempLEntity.equipPart == GeneralEnum.EQUIP_SLOT.BOTHHANDS) {//両手武器を装備中なら tempREntity.nowEquip = false; tempLEntity.nowEquip = false; weaponEntity.nowEquip = true; //右手左手のEntityを初期化 playerManager.equipWeapons[GeneralEnum.EQUIP_SLOT.RIGHTHAND] = new WeaponEntity(); playerManager.equipWeapons[GeneralEnum.EQUIP_SLOT.LEFTHAND] = new WeaponEntity(); playerManager.equipWeapons[equip_slot] = weaponEntity;//選択した武器を装備部位に代入する WeaponManager.instance.possessionWeapon[index] = new WeaponEntity(); if (tempREntity.isRegistry) WeaponManager.instance.RegiEntity(tempREntity); if (tempLEntity.isRegistry) WeaponManager.instance.RegiEntity(tempLEntity); //装備部位のテキストを反映する UpdateAllWeaponText(playerManager); } else//両手武器を装備していない場合 { if(equip_slot == GeneralEnum.EQUIP_SLOT.RIGHTHAND)//右手の場合 { //装備していた武器・防具の装備中フラグをfalseにする tempREntity.nowEquip = false; tempRHandAEntity.nowEquip = false; weaponEntity.nowEquip = true;//今から装備する武器の装備中フラグをtrueにする //右手の武器・防具を削除する playerManager.equipWeapons[GeneralEnum.EQUIP_SLOT.RIGHTHAND] = new WeaponEntity(); playerManager.equipArmors[GeneralEnum.EQUIP_SLOT.RIGHTHAND] = new ArmorEntity(); playerManager.equipWeapons[equip_slot] = weaponEntity;//選択した武器を装備部位に代入する。 WeaponManager.instance.possessionWeapon[index] = new WeaponEntity(); if (tempREntity.isRegistry) WeaponManager.instance.RegiEntity(tempREntity); if (tempRHandAEntity.isRegistry) ArmorManager.instance.RegiEntity(tempRHandAEntity); }else if (equip_slot == GeneralEnum.EQUIP_SLOT.LEFTHAND)//左手の場合 { //装備していた武器・防具の装備中フラグをfalseにする tempLEntity.nowEquip = false; tempLHandAEntity.nowEquip = false; weaponEntity.nowEquip = true;//今から装備する武器の装備中フラグをtrueにする //左手の武器・防具を削除する playerManager.equipWeapons[GeneralEnum.EQUIP_SLOT.LEFTHAND] = new WeaponEntity(); playerManager.equipArmors[GeneralEnum.EQUIP_SLOT.LEFTHAND] = new ArmorEntity(); playerManager.equipWeapons[equip_slot] = weaponEntity;//選択した武器を装備部位に代入する。 WeaponManager.instance.possessionWeapon[index] = new WeaponEntity(); if (tempLEntity.isRegistry) WeaponManager.instance.RegiEntity(tempLEntity); if (tempLHandAEntity.isRegistry) ArmorManager.instance.RegiEntity(tempLHandAEntity); } UpdateWeaponText(playerManager,weaponEntity,equip_slot); } }else if (weaponData.equipPart == GeneralEnum.EQUIP_SLOT.BOTHHANDS) {//新しく装備する武器が両手用なら //装備中フラグをfalseに tempREntity.nowEquip = false; tempLEntity.nowEquip = false; tempRHandAEntity.nowEquip = false; tempLHandAEntity.nowEquip = false; weaponEntity.nowEquip = true;//今から装備する武器のフラグをtrueに //右手左手のEntityを削除する playerManager.equipWeapons[GeneralEnum.EQUIP_SLOT.RIGHTHAND] = new WeaponEntity(); playerManager.equipWeapons[GeneralEnum.EQUIP_SLOT.LEFTHAND] = new WeaponEntity(); playerManager.equipArmors[GeneralEnum.EQUIP_SLOT.RIGHTHAND] = new ArmorEntity(); playerManager.equipArmors[GeneralEnum.EQUIP_SLOT.LEFTHAND] = new ArmorEntity(); //選択した武器を装備部位に代入する。 playerManager.equipWeapons[equip_slot] = weaponEntity; //選択した武器をリストから削除する WeaponManager.instance.possessionWeapon[index] = new WeaponEntity(); //リストに装備していた武器もしくは防具を代入する。 if (tempREntity.isRegistry) WeaponManager.instance.RegiEntity(tempREntity); if (tempLEntity.isRegistry) WeaponManager.instance.RegiEntity(tempLEntity); if (tempRHandAEntity.isRegistry) ArmorManager.instance.RegiEntity(tempRHandAEntity); if (tempLHandAEntity.isRegistry) ArmorManager.instance.RegiEntity(tempLHandAEntity); //装備部位のテキストを反映する UpdateAllWeaponText(playerManager); } //装備反映後の能力値を再計算する playerManager.CalcAllAfterEquipStatusValue();//New playerManager.CalcAllAfterEquipResiOfElementValue();//New playerManager.CalcAllAfterEquipResiOfStatusValue();//New SoundManager.instance.PlaySE(34); } public void ChangeArmor(GeneralEnum.EQUIP_SLOT equip_slot, ArmorEntity armorEntity, PlayerManager playerManager, int index) { //装備部位が右手か左手の場合 if(equip_slot==GeneralEnum.EQUIP_SLOT.RIGHTHAND || equip_slot == GeneralEnum.EQUIP_SLOT.LEFTHAND) { //右手・左手の装備をそれぞれチェックする ArmorEntity tempRHandAEntity; ArmorEntity tempLHandAEntity; WeaponEntity tempRHandWEntity; WeaponEntity tempLHandWEntity; //右手からチェック if (playerManager.equipArmors[GeneralEnum.EQUIP_SLOT.RIGHTHAND].nowEquip)//防具装備中なら { tempRHandAEntity = playerManager.equipArmors[GeneralEnum.EQUIP_SLOT.RIGHTHAND]; tempRHandWEntity = new WeaponEntity(); }else if (playerManager.equipWeapons[GeneralEnum.EQUIP_SLOT.RIGHTHAND].nowEquip)//武器装備中なら { tempRHandAEntity = new ArmorEntity(); tempRHandWEntity = playerManager.equipWeapons[GeneralEnum.EQUIP_SLOT.RIGHTHAND]; } else { tempRHandAEntity = new ArmorEntity(); tempRHandWEntity = new WeaponEntity(); } //左手からチェック if (playerManager.equipArmors[GeneralEnum.EQUIP_SLOT.LEFTHAND].nowEquip)//防具装備中なら { tempLHandAEntity = playerManager.equipArmors[GeneralEnum.EQUIP_SLOT.LEFTHAND]; tempLHandWEntity = new WeaponEntity(); } else if (playerManager.equipWeapons[GeneralEnum.EQUIP_SLOT.LEFTHAND].nowEquip)//武器装備中なら { tempLHandAEntity = new ArmorEntity(); tempLHandWEntity = playerManager.equipWeapons[GeneralEnum.EQUIP_SLOT.LEFTHAND]; } else { tempLHandAEntity = new ArmorEntity(); tempLHandWEntity = new WeaponEntity(); } //両手武器を装備していたら if(tempRHandWEntity.equipPart == GeneralEnum.EQUIP_SLOT.BOTHHANDS || tempLHandWEntity.equipPart == GeneralEnum.EQUIP_SLOT.BOTHHANDS) { tempRHandWEntity.nowEquip = false; tempLHandWEntity.nowEquip = false; armorEntity.nowEquip = true; //右手左手の装備を削除する playerManager.equipWeapons[GeneralEnum.EQUIP_SLOT.RIGHTHAND] = new WeaponEntity(); playerManager.equipWeapons[GeneralEnum.EQUIP_SLOT.LEFTHAND] = new WeaponEntity(); playerManager.equipArmors[equip_slot] = armorEntity;//選択した防具を装備部位に代入する。 UpdateArmorText(playerManager, playerManager.equipArmors[GeneralEnum.EQUIP_SLOT.RIGHTHAND], GeneralEnum.EQUIP_SLOT.RIGHTHAND); UpdateArmorText(playerManager, playerManager.equipArmors[GeneralEnum.EQUIP_SLOT.LEFTHAND], GeneralEnum.EQUIP_SLOT.LEFTHAND); //選択した防具をリストから削除する ArmorManager.instance.possessionArmor[index] = new ArmorEntity(); //リストに装備していた武器を代入する。(両手武器の場合は武器だけ処理すればいい.isRegistryがfalseなら装備されてない部位) if (tempRHandWEntity.isRegistry) WeaponManager.instance.RegiEntity(tempRHandWEntity); if (tempLHandWEntity.isRegistry) WeaponManager.instance.RegiEntity(tempLHandWEntity); } else//両手武器を装備していない場合 { if(equip_slot == GeneralEnum.EQUIP_SLOT.RIGHTHAND)//右手の場合 { //装備していた武器・防具の装備中フラグをfalseにする tempRHandWEntity.nowEquip = false; tempRHandAEntity.nowEquip = false; armorEntity.nowEquip = true;//今から装備する防具の装備中フラグをtrueにする //右手の武器・防具を削除する playerManager.equipWeapons[GeneralEnum.EQUIP_SLOT.RIGHTHAND] = new WeaponEntity(); playerManager.equipArmors[GeneralEnum.EQUIP_SLOT.RIGHTHAND] = new ArmorEntity(); playerManager.equipArmors[equip_slot] = armorEntity;//選択した防具を装備部位に代入する。 UpdateArmorText(playerManager, armorEntity, equip_slot); //選択した防具をリストから削除する ArmorManager.instance.possessionArmor[index] = new ArmorEntity(); //リストに装備していた武器もしくは防具を代入する。 if (tempRHandWEntity.isRegistry) WeaponManager.instance.RegiEntity(tempRHandWEntity); if (tempRHandAEntity.isRegistry) ArmorManager.instance.RegiEntity(tempRHandAEntity); } else if(equip_slot == GeneralEnum.EQUIP_SLOT.LEFTHAND)//左手の場合 { //装備していた武器・防具の装備中フラグをfalseにする tempLHandWEntity.nowEquip = false; tempLHandAEntity.nowEquip = false; armorEntity.nowEquip = true;//今から装備する防具の装備中フラグをtrueにする //右手の武器・防具を削除する playerManager.equipWeapons[GeneralEnum.EQUIP_SLOT.LEFTHAND] = new WeaponEntity(); playerManager.equipArmors[GeneralEnum.EQUIP_SLOT.LEFTHAND] = new ArmorEntity(); playerManager.equipArmors[equip_slot] = armorEntity;//選択した防具を装備部位に代入する。 UpdateArmorText(playerManager, armorEntity, equip_slot); //選択した防具をリストから削除する ArmorManager.instance.possessionArmor[index] = new ArmorEntity(); //リストに装備していた武器もしくは防具を代入する。 if (tempLHandWEntity.isRegistry) WeaponManager.instance.RegiEntity(tempLHandWEntity); if (tempLHandAEntity.isRegistry) ArmorManager.instance.RegiEntity(tempLHandAEntity); } } } else//装備部位が右手左手じゃない場合 { //現在装備中の防具を一時変数に入れる ArmorEntity tempEntity = playerManager.equipArmors[equip_slot]; //装備中フラグをfalseに tempEntity.nowEquip = false; armorEntity.nowEquip = true;//今から装備する防具のフラグをtrueに //選択した防具を装備部位に代入する。 playerManager.equipArmors[equip_slot] = armorEntity; //装備部位のテキストを反映する UpdateArmorText(playerManager, armorEntity, equip_slot); //リストに装備していた防具を代入する。 ArmorManager.instance.possessionArmor[index] = tempEntity; } //装備反映後の能力値を再計算する playerManager.CalcAllAfterEquipStatusValue();//New playerManager.CalcAllAfterEquipResiOfElementValue();//New playerManager.CalcAllAfterEquipResiOfStatusValue();//New SoundManager.instance.PlaySE(34); }
これで内部的には装備の変更によって数値が変更されるようになったのですが、見た目で確認することができないので、ステータス画面で装備を考慮した数値を確認できるようにしたいと思います。
ステータス画面の制御はPlayerStatusUIスクリプトで行っているのでこちらに処理を追加していきます。現状、PlayerManagerオブジェクトのインスペクターで設定した数値をそのまま表示しているのですが、それを装備反映後の数値とカッコ内に基本値を表示する形式に変更します。
クリックで展開
public void SetStatusText() { nameText.text = "名前 " + PlayerManager.instance.pname; hpText.text = "HP " + PlayerManager.instance.hp + " / " + PlayerManager.instance.afterEquipStatusValue[GeneralEnum.STATUS.HP] + "(" + PlayerManager.instance.baseStatusValue[GeneralEnum.STATUS.HP] + ")"; mpText.text = "MP " + PlayerManager.instance.mp + " / " + PlayerManager.instance.afterEquipStatusValue[GeneralEnum.STATUS.MP] + "(" + PlayerManager.instance.baseStatusValue[GeneralEnum.STATUS.MP] + ")"; tpText.text = "TP " + PlayerManager.instance.tp; atkText.text = "攻撃 " + PlayerManager.instance.afterEquipStatusValue[GeneralEnum.STATUS.ATK] + "(" + PlayerManager.instance.baseStatusValue[GeneralEnum.STATUS.ATK] + ")"; defText.text = "防御 " + PlayerManager.instance.afterEquipStatusValue[GeneralEnum.STATUS.DEF] + "(" + PlayerManager.instance.baseStatusValue[GeneralEnum.STATUS.DEF] + ")"; agiText.text = "速さ " + PlayerManager.instance.afterEquipStatusValue[GeneralEnum.STATUS.AGI] + "(" + PlayerManager.instance.baseStatusValue[GeneralEnum.STATUS.AGI] + ")"; lukText.text = "運 " + PlayerManager.instance.afterEquipStatusValue[GeneralEnum.STATUS.LUK] + "(" + PlayerManager.instance.baseStatusValue[GeneralEnum.STATUS.LUK] + ")"; senceText.text = "感覚 " + PlayerManager.instance.afterEquipStatusValue[GeneralEnum.STATUS.SENCE] + "(" + PlayerManager.instance.baseStatusValue[GeneralEnum.STATUS.SENCE] + ")"; magpowText.text = "魔力 " + PlayerManager.instance.afterEquipStatusValue[GeneralEnum.STATUS.MAGPOW] + "(" + PlayerManager.instance.baseStatusValue[GeneralEnum.STATUS.MAGPOW] + ")"; magdefText.text = "魔防 " + PlayerManager.instance.afterEquipStatusValue[GeneralEnum.STATUS.MAGDEF] + "(" + PlayerManager.instance.baseStatusValue[GeneralEnum.STATUS.MAGDEF] + ")"; learnAbiText.text = "習得 " + PlayerManager.instance.afterEquipStatusValue[GeneralEnum.STATUS.LEARNABI] + "(" + PlayerManager.instance.baseStatusValue[GeneralEnum.STATUS.LEARNABI] + ")"; }
実行すると以下の動画のようになります。
次回は属性耐性値と状態異常のかかりやすさの値を確認できるUIを作成したいと思います。