Page MenuHomeFeedback Tracker

PlayerStatsPCO_Base - not moddable correctly right now
Assigned, UrgentPublic

Description

At the moment in the game it looks like this:

class PlayerStatsPCO_Base
{
	void PlayerStatsPCO_Base()
	{
		Init();
	}
	
	void Init();
	
	int GetVersion()
	{
		return -1;
	}
	
	ref array<ref PlayerStatBase> m_PlayerStats = new array<ref PlayerStatBase>;
	
	PlayerStatBase GetStatObject(int id)
	{
		return m_PlayerStats.Get(id);
	}
	
	void RegisterStat(int id, PlayerStatBase stat)
	{
		m_PlayerStats.InsertAt(stat, id);
		stat.Init(id/*, this*/);
	}
	
	void OnStoreSave ( ParamsWriteContext ctx )
	{
		for ( int i = 0; i < m_PlayerStats.Count(); i++ )
		{
			m_PlayerStats.Get(i).OnStoreSave(ctx);
		}
	}
	
	bool OnStoreLoad ( ParamsReadContext ctx )
	{
		for ( int i = 0; i < m_PlayerStats.Count(); i++ )
		{
			if(!m_PlayerStats.Get(i).OnStoreLoad(ctx))
			{
				return false;
			}
		}
		return true;
	}
	
	array<ref PlayerStatBase> Get()
	{
		return m_PlayerStats;
	}
	
	void ResetAllStats()
	{
		m_PlayerStats.Clear();
		Init();
	}
}

This problem happens because PlayerStatsPCO_Base using array as a storage PlayerStatBase.

I provide below the solution to this problem:

class PlayerStatsPCO_Base
{
    protected ref map<int,ref PlayerStatBase> m_NewPlayerStats;
	
	void PlayerStatsPCO_Base()
	{
		m_NewPlayerStats = new map<int,ref PlayerStatBase>;

		Init();
	}
	
	void Init();
	
	int GetVersion()
	{
		return -1;
	}
	
	PlayerStatBase GetStatObject(int id)
	{
		return m_NewPlayerStats.Get(id);
	}
	
	void RegisterStat(int id, PlayerStatBase stat)
	{
        m_NewPlayerStats.Insert(id,stat);
		stat.Init(id);
	}
	
	void OnStoreSave( ParamsWriteContext ctx )
	{
		for ( int i = 0; i < m_NewPlayerStats.Count(); i++ )
		{
			m_NewPlayerStats.GetElement(i).OnStoreSave(ctx);
		}
	}
	
	bool OnStoreLoad( ParamsReadContext ctx )
	{
		for ( int i = 0; i < m_NewPlayerStats.Count(); i++ )
		{
			if(!m_NewPlayerStats.GetElement(i).OnStoreLoad(ctx))
			{
				return false;
			}
		}
		return true;
	}
	
	array<ref PlayerStatBase> Get()
	{
		array<ref PlayerStatBase> temp = new array<ref PlayerStatBase>;
		temp.Copy(m_NewPlayerStats.GetValueArray());
		return temp;
	}
	
	void ResetAllStats()
	{
		m_NewPlayerStats.Clear();
		Init();
	}
}

Details

Severity
None
Resolution
Open
Reproducibility
Always
Operating System
Windows 10 x64
Category
General

Event Timeline

Demands created this task.Oct 6 2023, 9:01 PM
Demands updated the task description. (Show Details)
Geez changed the task status from New to Assigned.Oct 9 2023, 10:10 AM