edited August 2021 in ORK Scripting
Question1
I don't understand why player.Inventory.Has does not return True.

When you buy a weapon, you are calling BuyItem().
Initialize() is also called in BuyItem().
player.Inventory.Has() is called in Initialize().
After BuyItem Button Click,Equip Button will press by player.
Equip() is called when the equip button is pressed.
Initialize() is also called in Equip().
However, the Inventory.Has() in the Initialize() called in Equip() does not return True.
Has() does not return True. If it does, I want to deactivate the equip button and activate the "Equipped" button.
However, I'm expecting the purchased weapon to be True, but it turns out to be False.
If I call Initialize() twice Equip() call, Has() becomes True.

Why is this not happening?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ORKFramework;
using ORKFramework.Behaviours;
using TMPro;
using Cysharp.Threading.Tasks;
using UnityEngine.UI;
using Michsky.UI.ModernUIPack;
using UniRx;

public class UIViewWeaponsListItemPresenter : MonoBehaviour
{
private Combatant player;

public GameObject iconImageObj;
public GameObject lvlTextObj;
public GameObject nextLevelProgressBarObj;
public GameObject lvlUpButtonObj;
public GameObject buyButtonObj;
public GameObject equipButtonObj;
public GameObject atkStatusTextObj;
public GameObject nextExpTextObj;
public GameObject itemNameObj;
public GameObject lockObj;
EquipShortcut playerWeapon;
Weapon myWeapon;
public GameObject inEquipButtonObj;
EquipShortcut weaponShortcut;


// Start is called before the first frame update
void Start()
{
Initialize();
}

public void Initialize()
{
player = ORK.Game.ActiveGroup.Leader;
int myItemID = int.Parse(gameObject.name);
myWeapon = ORK.Weapons.Get(myItemID);
iconImageObj.GetComponent<RawImage>().texture = myWeapon.GetIcon();
itemNameObj.GetComponent<TextMeshProUGUI>().text = myWeapon.GetName();

if (weaponShortcut == null) weaponShortcut = new EquipShortcut(EquipSet.Weapon, myWeapon.ID, 1, 1);

Debug.Log("equip0");

//ここ以下は playerが所持している場合のみ処理
//if (!player.Inventory.Weapons.Contains(myItemID))
//EquipShortcut weaponShortcut = new EquipShortcut(EquipSet.Weapon, myWeapon.ID, 1, 1);

if (!player.Inventory.Has(weaponShortcut))
{
Debug.Log("player not have this weapon");
return;
}

lockObj.SetActive(false);
buyButtonObj.SetActive(false);
equipButtonObj.SetActive(true);
// 装備中は装備中ボタンのみアクティブ
//EquipShortcut item = new EquipShortcut(EquipSet.Weapon, myWeapon.ID, 1, 1);


Debug.Log("equip1");
if (player.Equipment.Parts[0].Equipment.ID == myItemID)
{
Debug.Log("equip1 if");
equipButtonObj.SetActive(false);
inEquipButtonObj.SetActive(true);
}

playerWeapon = player.Inventory.Weapons.Get(myItemID);

lvlTextObj.GetComponent<TextMeshProUGUI>().text = playerWeapon.Level.ToString();
var currentItemExp = player.Status[MyGame.CombatantStatusValue.ItemExp].GetValue();
float currentPercent = ((float)currentItemExp / (float)playerWeapon.MaxLevelPoints) * 100;
nextLevelProgressBarObj.GetComponent<ProgressBar>().currentPercent = currentPercent;
//nextLevelProgressBarObj.GetComponent<ProgressBar>().currentPercent = (player.Status[MyGame.CombatantStatusValue.ItemExp].GetValue() - playerWeapon.MaxLevelPoints) * 100;
atkStatusTextObj.GetComponent<TextMeshProUGUI>().text = "+Atk:" + playerWeapon.GetStatusValueBonus(player, MyGame.CombatantStatusValue.Atk).ToString();
nextExpTextObj.GetComponent<TextMeshProUGUI>().text = "NextLvExp:" + playerWeapon.MaxLevelPoints.ToString();

lvlUpButtonObj.GetComponent<Button>().onClick.AddListener(() => { OnLvlUpButtonClick(playerWeapon);});
equipButtonObj.GetComponent<Button>().onClick.AddListener(() => { OnEquipbuttonClick(); });
}

// インスペクタから設定
public void Equip()
{
player.Equipment.Equip(MyGame.CombatantEquipmentPart.メイン武器, weaponShortcut, player, player, false);
Debug.Log("equip");

Initialize();
}

public void BuyItem()
{
player.Inventory.Add(weaponShortcut, true, true, true);
player.Inventory.SubMoney(0, myWeapon.price.GetBuyPrice(player, null, null),true,true);

Initialize();
}
}


Question2
Since ORK is characterized as "All data can be accessed from the script," I am trying to use Script, but as in Question 1, I stumble over a few steps.
It is very difficult to operate ORK from Script, because we don't know the meaning of the functions, the properties are not disclosed, and the same functions as the nodes are not available.
I have read the Has property in Inventory.cs, but even problems like Question 1 cannot be solved without asking here every time.

Is there any way to make it easier?
Post edited by joeee19 on
  • 1) If a weapon or armor is equipped, it no longer is in the inventory.

    2) No - ORK is a massive framework with tens of thousands of settings, functions and features.
    Some things, as e.g. question 1, are also just a misunderstanding, e.g. an equipped weapon no longer being in the inventory.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
Sign In or Register to comment.