// C_Skill public void HandleSkill(Player player, C_Skill skillPacket) { if (player == null) { return; } ObjectInfo info = player.Info; if (info.PosInfo.State != CreatureState.Idle) { return; } // TODO : 스킬 사용가능한지 검증 // 통과 info.PosInfo.State = CreatureState.Skill; S_Skill skill = new S_Skill() { Info = new SkillInfo() }; skill.ObjectId = info.ObjectId; skill.Info.SkillId = skillPacket.Info.SkillId; // 유저가 보내준 스킬 Broadcast(player.CellPos, skill); Data.Skill skillData = null; if (DataManager.SkillDict.TryGetValue(skill.Info.SkillId, out skillData) == false) { return; } // 스킬 종류에 따른 로직 switch (skillData.skillType) { case SkillType.SkillAuto: // 평타 // 데미지 판정 Vector2Int skillPos = player.GetFrontCellPos(info.PosInfo.MoveDir); GameObject target = Map.Find(skillPos); if (target != null) { this.Push(target.OnDamaged, player, player.Info.StatInfo.Attack); } break; case SkillType.SkillProjectile: // 투사체 SpawnProjectile(player, skillData); break; case SkillType.SkillNone: break; default: return; } }
public void HandleSkill(Player player, C_Skill skillPacket) { if (player == null) { return; } ObjectInfo info = player.Info; if (info.PosInfo.State != CreatureState.Idle) { return; } // TODO : 스킬 사용 가능 여부 체크 info.PosInfo.State = CreatureState.Skill; S_Skill skill = new S_Skill() { Info = new SkillInfo() }; skill.ObjectId = info.ObjectId; skill.Info.SkillId = skillPacket.Info.SkillId; Broadcast(skill); Data.Skill skillData = null; if (DataManager.SkillDict.TryGetValue(skillPacket.Info.SkillId, out skillData) == false) { return; } switch (skillData.skillType) { case SkillType.SkillAuto: { Vector2Int skillPos = player.GetFrontCellPos(info.PosInfo.MoveDir); GameObject target = Map.Find(skillPos); if (target != null) { Console.WriteLine("Hit GameObject !"); } } break; case SkillType.SkillProjectile: { Arrow arrow = ObjectManager.Instance.Add <Arrow>(); if (arrow == null) { return; } arrow.Owner = player; arrow.Data = skillData; arrow.PosInfo.State = CreatureState.Moving; arrow.PosInfo.MoveDir = player.PosInfo.MoveDir; arrow.PosInfo.PosX = player.PosInfo.PosX; arrow.PosInfo.PosY = player.PosInfo.PosY; arrow.Speed = skillData.projectile.speed; Push(EnterGame, arrow); } break; } }
// GameRoom의 JobSerilizer에 의해 실행되기 때문에 EnterGame같은거 직접 불러도 됨 public void HandleSkill(Player player, C_Skill skillPacket) { if (player == null) // player가 지금 GameRoom에 소속되었는지도 체크 { return; } // 스킬분기처리.. 몇 개 없다는 가정하에 // 스킬이 많아지면 Skill 클래스를 따로 파서 플레이어에 주입하는게 낫다 ObjectInfo info = player.Info; if (info.PosInfo.State != CreatureState.Idle) { return; } // 스킬 사용 가능 여부 체크 // 스킬 애니메이션 맞춰주는 부분 info.PosInfo.State = CreatureState.Skill; S_Skill skill = new S_Skill() { Info = new SkillInfo() }; // info도 클래스임 skill.ObjectId = info.ObjectId; skill.Info.SkillId = skillPacket.Info.SkillId; // 나중에 시트로 뺄거야 Broadcast(skill); // 에코서버마냥 전파한다 // 이제 DB에서 Id에 해당하는 스킬데이터를 뽑아온다 Data.Skill skillData = null; if (DataManager.SkillDict.TryGetValue(skillPacket.Info.SkillId, out skillData) == false) { return; } // id에 해당하는 스킬이 있다 switch (skillData.skillType) { case SkillType.SkillAuto: { // 주먹질 // 데미지 판정 -> 항상 치팅 대비 // 내 공격방향에 적이 있나 없나 체크 // GetFrontCellPos에 MoveDir.None 처리가 없으니 // 항상 공격자의 위치를 반환해서 아무대나 떄려도 타격이 되는 문제가 있었음 // MoveDir.None이 그냥 키입력 여부를 받는거라 서버에는 필요없으므로 전체적으로 없애기로함 Vector2Int skillPos = player.GetFrontCellPos(info.PosInfo.MoveDir); GameObject target = Map.Find(skillPos); if (target != null) { Console.WriteLine("Hit GameObject!"); } } break; case SkillType.SkillProjectile: { // 화살 생성 // 클라에서도 화살이 날아가는것을 계산하고 있어야 치팅을 방지할수 있다. // 어떤 투사체인지 구분할수 있는게 필요 (지금은 화살만..) Arrow arrow = ObjectManager.Instance.Add <Arrow>(); if (arrow == null) { return; } // 데이터 대입 arrow.Owner = player; arrow.Data = skillData; // 투사체를 생성한 주체(스킬)의 정보를 저장 arrow.PosInfo.State = CreatureState.Moving; arrow.PosInfo.MoveDir = player.PosInfo.MoveDir; arrow.PosInfo.PosX = player.PosInfo.PosX; arrow.PosInfo.PosY = player.PosInfo.PosY; arrow.Speed = skillData.projectile.speed; // 직접 불러서 해도 전혀 문제없긴함 EnterGame(arrow) Push(EnterGame, arrow); // 치팅방지 + 코드재사용(화살이 생성됐음을 모두에게 알림) } break; } }