public void AddCreature(OtCreature creature) { if (!creatures.ContainsKey(creature.Id)) { var spawnLocation = new Location(creature.Location.X - (creature.Location.X % SPAWN_SIZE) + SPAWN_RADIUS, creature.Location.Y - (creature.Location.Y % SPAWN_SIZE) + SPAWN_RADIUS, creature.Location.Z); var spawnIndex = spawnLocation.ToIndex(); if (!spawns.ContainsKey(spawnIndex)) { spawns.Add(spawnIndex, new OtSpawn(spawnLocation, SPAWN_RADIUS)); } var spwan = spawns[spawnIndex]; if (spwan.AddCreature(creature)) { if (creature.Type == CreatureType.NPC) { npcCount++; } else if (creature.Type == CreatureType.MONSTER) { monsterCount++; } creatures.Add(creature.Id, creature); } } }
public bool AddCreature(OtCreature creature) { var relativeLocation = GetRelativeLocation(creature.Location); if (!(Math.Abs(relativeLocation.X) <= Radius && Math.Abs(relativeLocation.Y) <= Radius)) { throw new Exception("Can't add this creature to this spawn. Spawn Location: " + Location + ", Creature Location: " + creature.Location); } creature.Location = relativeLocation; if (creatures[relativeLocation.X + Radius, relativeLocation.Y + Radius] == null) { creatures[relativeLocation.X + Radius, relativeLocation.Y + Radius] = creature; return(true); } return(false); }