/// <summary> /// Create a new monster. /// </summary> /// <param name="moverData">Monster's data</param> /// <param name="respawnRegion">Respawn region</param> /// <returns></returns> private MonsterEntity CreateMonster(MoverData moverData, IMapRespawnRegion respawnRegion) { var monster = new MonsterEntity(this); var behaviors = DependencyContainer.Instance.Resolve <BehaviorLoader>(); monster.Object = new ObjectComponent { MapId = this.Parent.Id, LayerId = this.Id, ModelId = moverData.Id, Type = WorldObjectType.Mover, Position = respawnRegion.GetRandomPosition(), Angle = RandomHelper.FloatRandom(0, 360f), Name = moverData.Name, Size = ObjectComponent.DefaultObjectSize, Spawned = true, Level = moverData.Level }; monster.Timers = new TimerComponent { NextMoveTime = RandomHelper.LongRandom(8, 20) }; monster.MovableComponent = new MovableComponent { Speed = moverData.Speed, DestinationPosition = monster.Object.Position.Clone() }; monster.Health = new HealthComponent { Hp = moverData.AddHp, Mp = moverData.AddMp, Fp = 0 }; monster.Statistics = new StatisticsComponent { Strength = (ushort)moverData.Strength, Stamina = (ushort)moverData.Stamina, Dexterity = (ushort)moverData.Dexterity, Intelligence = (ushort)moverData.Intelligence }; monster.Behavior = behaviors.MonsterBehaviors.GetBehavior(monster.Object.ModelId); monster.Region = respawnRegion; monster.Data = moverData; if (moverData.Class == MoverClassType.RANK_BOSS) { monster.Object.Size *= 2; } return(monster); }
/// <summary> /// Creates a permanant drop item. /// </summary> /// <remarks> /// Mainly used for quest items. /// </remarks> /// <param name="itemData">Item data</param> /// <param name="respawnRegion">Respawn region</param> /// <returns>A new ItemEntity</returns> private ItemEntity CreateWorldItem(ItemData itemData, IMapRespawnRegion respawnRegion) { var item = new ItemEntity(this); item.Drop.Item = new Item(itemData.Id, 1); item.Drop.RespawnTime = respawnRegion.Time; item.Region = respawnRegion; item.Object = new ObjectComponent { MapId = this.Parent.Id, LayerId = this.Id, ModelId = respawnRegion.ModelId, Type = WorldObjectType.Item, Position = respawnRegion.GetRandomPosition(), Angle = RandomHelper.FloatRandom(0, 360f), Name = itemData.Name, Size = ObjectComponent.DefaultObjectSize, Spawned = true, }; return(item); }
/// <inheritdoc /> public IMonsterEntity CreateMonster(IMapInstance currentMap, IMapLayer currentMapLayer, int moverId, IMapRespawnRegion region, bool respawn = false) { if (!_gameResources.Movers.TryGetValue(moverId, out MoverData moverData)) { throw new ArgumentException($"Cannot find mover with id '{moverId}' in game resources.", nameof(moverId)); } var monster = new MonsterEntity { Object = new ObjectComponent { ModelId = moverId, Name = moverData.Name, Level = moverData.Level, Type = WorldObjectType.Mover, Size = ObjectComponent.DefaultObjectSize, MovingFlags = ObjectState.OBJSTA_STAND, Position = region.GetRandomPosition(), Angle = RandomHelper.FloatRandom(0, 360f), Spawned = true, AbleRespawn = respawn, CurrentMap = currentMap, LayerId = currentMapLayer.Id }, Timers = new TimerComponent { NextMoveTime = Time.TimeInSeconds() + RandomHelper.LongRandom(8, 20) } }; monster.Moves = new MovableComponent { Speed = moverData.Speed }; monster.Data = moverData; monster.Region = region; monster.Attributes[DefineAttributes.HP] = moverData.AddHp; monster.Attributes[DefineAttributes.MP] = moverData.AddMp; monster.Attributes[DefineAttributes.STR] = moverData.Strength; monster.Attributes[DefineAttributes.STA] = moverData.Stamina; monster.Attributes[DefineAttributes.DEX] = moverData.Dexterity; monster.Attributes[DefineAttributes.INT] = moverData.Intelligence; monster.Behavior = _behaviorManager.GetBehavior(BehaviorType.Monster, monster, moverId); monster.Hand = _itemFactory.CreateItem(11, 0, ElementType.None, 0); if (moverData.Class == MoverClassType.RANK_BOSS) { monster.Object.Size *= 2; } return(monster); }