private void ChangePlayerArea(RemotePlayer p, string connectionId, string targetArea) { if (targetArea == "Town") { p.GetPlayerShape().insafezone = true; p.GetPlayerShape().lastbattletimer = 0; } else if (targetArea == "Overworld") { p.GetPlayerShape().insafezone = false; p.GetPlayerShape().lastbattletimer = 0; } Vec2 fromareapos = gameData.maps[targetArea].triggerareas[p.areaname].getCenter(); p.Teleport(fromareapos); PlayerLeftArea(connectionId, p); //delete player from areas playerlist mapstates[p.areaname].playerlist.Remove(p.GetPlayerShape()); //add the player to the new area mapstates[targetArea].playerlist.Add(p.GetPlayerShape()); p.areaname = targetArea; PlayerJoinedArea(connectionId, p); _broadcaster.MovePlayerInNewZone(connectionId, fromareapos); }
public void Message(string cmd, string attribs, string connectionId) { RemotePlayer p; if (!connectedPlayers.TryGetValue(connectionId, out p)) { Debug.WriteLine("Message called with playerless connectionId"); return; } if (cmd == "areachangetrigger") { if (gameData.maps.ContainsKey(attribs)) { if (Collision.TestCircleCollision(p.GetPosition(), 50, gameData.maps[p.areaname].triggerareas[attribs].getCenter(), 50)) { ChangePlayerArea(p, connectionId, attribs); } } } else if (cmd == "playerhittrigger") { List <CollisionCircle> posCollisions = new List <CollisionCircle>(); overworldcollisions.Retrieve(posCollisions, new CollisionCircle(p.getCollCircle())); foreach (var collision in posCollisions) { if (Collision.TestCircleCollision(p.GetPosition(), 50, collision.getCenter(), 50)) { if (collision.getType() == CollisionCircle.ObjectType.PLAYER) { RemotePlayer rp = (RemotePlayer)collision.getObject(); if (rp != p && (int)rp.GetPlayerShape().id == int.Parse(attribs)) { if (rp.currentbattle != null) { // Battle b = new Battle(p, rp); // battles.Add(b); // _broadcaster.StartBattle(b); } } } } } } else if (cmd == "npchittrigger") { List <CollisionCircle> posCollisions = new List <CollisionCircle>(); overworldcollisions.Retrieve(posCollisions, new CollisionCircle(p.getCollCircle())); foreach (var collision in posCollisions) { if (Collision.TestCircleCollision(p.GetPosition(), 50, collision.getCenter(), 100)) { if (collision.getType() == CollisionCircle.ObjectType.NPC) { Npc npc = (Npc)collision.getObject(); if (npc.state != Npc.NPC_STATE.BATTLE) { // Battle b = new Battle(npc, p); // npc.state = Npc.NPC_STATE.BATTLE; // battles.Add(b); // _broadcaster.StartBattle(b); } } } } } }