public override void Update() { if (Data == null || Data.projectile == null || Owner == null || Room == null) { return; } int tick = (int)(1000 / Data.projectile.speed); Room.PushAfter(tick, Update); Vector2Int destPos = GetFrontCellPos(); if (Room.Map.ApplyMove(this, destPos, collision: false)) { S_Move movePacket = new S_Move(); movePacket.ObjectId = Id; movePacket.PosInfo = PosInfo; Room.Broadcast(CellPos, movePacket); //Console.WriteLine("Move Arrow"); } else { GameObject target = Room.Map.Find(destPos); if (target != null) { target.OnDamaged(this, Data.damage + Owner.TotalAttack); } // 소멸 Room.Push(Room.LeaveGame, Id); } }
// 무조건 게임 전체 틱을 따라갈 이유가 없다 public override void Update() { if (Data == null || Data.projectile == null || Owner == null || Room == null) { return; } if (_nextMoveTick >= Environment.TickCount64) { return; } // 틱돌아옴 // speed 는 1초에 움직일수 있는 칸의 개수 // 1초는 1000ms니까 이걸 speed 값으로 나눠서 // 다음 1칸 이동까지 내가 얼마나 기다려야 하는지(ms) 구함 long tick = (long)(1000 / Data.projectile.speed); _nextMoveTick = Environment.TickCount64 + tick; // 1칸 이동 처리 Vector2Int destPos = GetFrontCellPos(); // 내가 진행하는 방향의 바로 앞 좌표 if (Room.Map.CanGo(destPos)) { CellPos = destPos; S_Move movePacket = new S_Move(); movePacket.ObjectId = Id; movePacket.PosInfo = PosInfo; Room.Broadcast(movePacket); Console.WriteLine("Move Arrow"); } else { // 화살이 가다 막힘 GameObject target = Room.Map.Find(destPos); // 벽이 아니고 게임 캐릭터였으면? if (target != null) { // 아야 -> 피를 어디서 깎을거냐? -> 맞은쪽이 처리 (맞은쪽의 스펙(버프) 계산때문에 얻어맞은쪽이 직접 처리하는게 편함) // 공격자 자체를 넣을지 나를 때린 오브젝트를 넣을지? // 여기서는 공격자 자체를 넣었는데, owner변수로 누가 공격했는지도 알 수 있다 target.OnDamaged(this, Data.damage + Owner.Stat.Attack); Console.WriteLine($"Damage : {Data.damage + Owner.Stat.Attack}"); } // 벽쾅 -> 소멸 Room.Push(Room.LeaveGame, Id); } }
public override void Update() { if (Data == null || Owner == null || Room == null) { return; } if (Data.projectile == null) { return; } if (_nextMoveTick >= Environment.TickCount64) { return; } long tick = (long)(1000 / Data.projectile.speed); _nextMoveTick = Environment.TickCount64 + tick; Vector2int destPos = GetFrontCellPos(); if (Room._Map.CanGo(destPos)) { CellPos = destPos; S_Move movePacket = new S_Move(); movePacket.ObjectId = Id; movePacket.PosInfo = PosInfo; Room.BroadCast(movePacket); Console.WriteLine("Move Arrow"); } else { GameObject target = Room._Map.Find(destPos); if (target != null) { // 피격 판정 target.OnDamaged(this, Data.damage + Owner.Stat.Attack); //Console.WriteLine($"damage : {Data.damage}"); } // 소멸 Room.Push(Room.LeaveGame, Id); } }
public override void Update() { // 유효성 검사 if (Data == null || Data.projectile == null || Owner == null || Room == null) { return; } int tick = (int)(1000 / Data.projectile.speed); // 1초에 speed칸만큼 움직임 Room.PushAfter(tick, Update); // 자기 자신을 예약 // TODO 앞으로 나가기 / 뿌려주기 Vector2Int destPos = GetFrontCellPos(); if (Room.Map.ApplyMove(this, destPos, collision: false) == true) { S_Move movePacket = new S_Move(); movePacket.ObjectId = Id; movePacket.PosInfo = PosInfo; Room.Broadcast(CellPos, movePacket); //Console.WriteLine("Move Arrow"); } else { GameObject target = Room.Map.Find(destPos); if (target != null) { // 피격판정 //Console.WriteLine($"{target.Info.Name} Damaged : {Data.damage}"); target.OnDamaged(this, Data.damage + Owner.TotalAttack); } // 소멸 //Room.LeaveGame(Id); Room.Push(Room.LeaveGame, Id); } }