/// <inheritdoc /> public IMapLayer CreateLayer(IMapInstance parentMapInstance, int layerId) { var mapLayer = ActivatorUtilities.CreateInstance <MapLayer>(_serviceProvider, parentMapInstance, layerId); foreach (IMapRegion region in parentMapInstance.Regions) { if (region is IMapRespawnRegion respawnRegion) { if (respawnRegion.ObjectType == WorldObjectType.Mover) { for (int i = 0; i < respawnRegion.Count; i++) { IMonsterEntity monster = _monsterFactory.CreateMonster(parentMapInstance, mapLayer, respawnRegion.ModelId, respawnRegion); mapLayer.AddEntity(monster); } } else if (respawnRegion.ObjectType == WorldObjectType.Item) { var item = _itemFactory.CreateItem(respawnRegion.ModelId, 0, 0, 0); for (int i = 0; i < respawnRegion.Count; ++i) { IItemEntity itemEntity = _itemFactory.CreateItemEntity(parentMapInstance, mapLayer, item); itemEntity.Object.Position = respawnRegion.GetRandomPosition(); itemEntity.Region = respawnRegion; mapLayer.AddEntity(itemEntity); } } } } return(mapLayer); }
public CombatEngine(GameWorld gameWorld, IMonsterFactory monsterFactory, ICombatantSelector combantSelector, IDice dice) { _gameWorld = gameWorld; _combantSelector = combantSelector; _dice = dice; _combatContext = new CombatContext(); _combatContext.Player = _gameWorld.Player; _combatContext.Monster = monsterFactory.CreateMonster(_gameWorld, _combatContext); _combatContext.Player.HasFledCombat = false; _combatContext.Monster.HasFledCombat = false; }
/// <inheritdoc /> public void Execute(IPlayerEntity player, object[] parameters) { if (parameters.Length <= 0 || parameters.Length > 2) { throw new ArgumentException($"Create monster command must have 1 or 2 parameters.", nameof(parameters)); } if (!int.TryParse((string)parameters[0], out int monsterId)) { throw new ArgumentException($"Cannot convert the first parameter in int.", nameof(parameters)); } int quantityToSpawn = 1; if (parameters.Length == 2) { if (!int.TryParse((string)parameters[1], out quantityToSpawn)) { throw new ArgumentException($"Cannot convert the second parameter in int.", nameof(parameters)); } } _logger.LogTrace($"{player.Object.Name} want to spawn {quantityToSpawn} mmonster"); const int sizeOfSpawnArea = 13; const int respawnTime = 65535; IMapInstance currentMap = player.Object.CurrentMap; IMapLayer currentMapLayer = currentMap.GetMapLayer(player.Object.LayerId); Vector3 currentPosition = player.Object.Position.Clone(); var respawnRegion = new MapRespawnRegion((int)currentPosition.X - sizeOfSpawnArea / 2, (int)currentPosition.Z - sizeOfSpawnArea / 2, sizeOfSpawnArea, sizeOfSpawnArea, respawnTime, WorldObjectType.Mover, monsterId, quantityToSpawn); for (int i = 0; i < quantityToSpawn; i++) { IMonsterEntity monsterToCreate = _monsterFactory.CreateMonster(currentMap, currentMapLayer, monsterId, respawnRegion, true); monsterToCreate.Object.Position = player.Object.Position.Clone(); currentMapLayer.AddEntity(monsterToCreate); } }
protected virtual IEnumerable <IMonster> CreateMonsters(IMonsterFactory factory) { return(Enumerable.Repeat <MonsterType>(this.MonsterType, this.Count).Select(type => factory.CreateMonster(type))); }
public void LoadMonster(IMonsterFactory monsterFactory) { Monster = monsterFactory.CreateMonster(MonsterId); Monster.Health = Health; }