스탯

Eunho Bae·2022년 6월 25일

목표

서버에서 받아온 정보를 가지고 플레이어, 화살 등 속도를 결정하도록 함

Protocol.proto

message S_EnterGame {
  ObjectInfo player = 1;
}

message ObjectInfo {
  int32 objectId = 1;
  string name = 2;
  PositionInfo posInfo = 3;
  StatInfo statInfo = 4;
}

message StatInfo {
  int32 hp = 1;
  int32 maxHp = 2;
  float speed = 3;
}

서버에서 S_EnterGame 패킷을 클라이언트에게 보낼때 ObjectInfo를 보내는데 이곳에 StatInfo를 추가해주었다.

Server::Player

public class Player : GameObject
	{
		public ClientSession Session { get; set; }

		public Player()
		{
			ObjectType = GameObjectType.Player;
			Speed = 10.0f;
		}

Server::GameObject

		...

		public StatInfo Stat { get; private set; } = new StatInfo();

		public float Speed
        {
			get { return Stat.Speed; }
			set { Stat.Speed = value; }	
        }

		public GameObject()
		{
			Info.PosInfo = PosInfo;
			Info.StatInfo = Stat;
		}
        
        ...

Client::CreatureController

StatInfo _stat = new StatInfo();

	public StatInfo Stat
    {
		get { return _stat; }
        set
        {
			if (_stat.Equals(value))
				return;

			_stat.Hp = value.Hp;
			_stat.MaxHp = value.MaxHp;	
			_stat.Speed = value.Speed;
        }
    }

	public float Speed
    {
		get { return Stat.Speed; }
        set { Stat.Speed = value; }
    }

Client::ObjectManager

public void Add(ObjectInfo info, bool myPlayer = false)
{
	if (objectType == GameObjectType.Player)
	{
		if (myPlayer)
		{
        	...
			MyPlayer.Stat = info.StatInfo;
            ...
        }
        else
		{
        	...
			pc.Stat = info.StatInfo;
            ...
        }
    }
    else if (objectType == GameObjectType.Projectile)
	{
    	...
        ArrowController ac = go.GetComponent<ArrowController>();
		ac.PosInfo = info.PosInfo;
		ac.Stat = info.StatInfo;

		// 서버에서 받아온 정보를 가지고 플레이어, 화살 등 속도 결정
    	...
    }
}
    
profile
개인 공부 정리

0개의 댓글