Beispiel #1
0
        private Item GetItemDrop(MonsterDefinition monster, DropItemGroup selectedGroup)
        {
            if (selectedGroup != null)
            {
                if (selectedGroup.PossibleItems?.Count > 0)
                {
                    var item = new TemporaryItem();
                    item.Definition = selectedGroup.PossibleItems.SelectRandom(this.randomizer);
                    this.ApplyRandomOptions(item);
                    return(item);
                }

                switch (selectedGroup.ItemType)
                {
                case SpecialItemType.Ancient:
                    return(this.GetRandomAncient());

                case SpecialItemType.Excellent:
                    return(this.GetRandomExcellentItem((int)monster[Stats.Level]));

                case SpecialItemType.RandomItem:
                    return(this.GetRandomItem((int)monster[Stats.Level], false));

                case SpecialItemType.SocketItem:
                    return(this.GetRandomItem((int)monster[Stats.Level], true));

                default:
                    // none
                    return(null);
                }
            }

            return(null);
        }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NonPlayerCharacter"/> class.
 /// </summary>
 /// <param name="spawnInfo">The spawn information.</param>
 /// <param name="stats">The stats.</param>
 /// <param name="id">The identifier.</param>
 /// <param name="map">The map on which this instance will spawn.</param>
 public NonPlayerCharacter(MonsterSpawnArea spawnInfo, MonsterDefinition stats, ushort id, GameMap map)
 {
     this.Id         = id;
     this.SpawnArea  = spawnInfo;
     this.Definition = stats;
     this.CurrentMap = map;
 }
        private void LoadMonsterDefinitions()
        {
            AvailableMonsters = new Dictionary <int, MonsterDefinition>();

            MonsterDefinition goblinDefinition = new MonsterDefinition()
            {
                Name           = "goblin",
                DefinitiveForm = "the goblin",
                AttackVerb     = "hits",
                Symbol         = Assets.MonsterSymbols.Goblins[0],
                Movement       = MonsterMovementType.Walk,

                MaxHP        = 24,
                MaxMP        = 0,
                Strength     = 7,
                Constitution = 7,
                Dexterity    = 7,
                Intelligence = 7,
                Luck         = 7,

                Armour  = 0,
                Evasion = 0
            };

            AvailableMonsters.Add(0, goblinDefinition);
        }
Beispiel #4
0
        private INpcIntelligence TryCreateConfiguredNpcIntelligence(MonsterDefinition monsterDefinition, GameMap createdMap)
        {
            if (string.IsNullOrWhiteSpace(monsterDefinition.IntelligenceTypeName))
            {
                return(null);
            }

            try
            {
                var type = Type.GetType(monsterDefinition.IntelligenceTypeName);
                if (type is null)
                {
                    this.logger.LogError($"Could not find type {monsterDefinition.IntelligenceTypeName}");
                    return(null);
                }

                return((INpcIntelligence)Activator.CreateInstance(type, createdMap));
            }
            catch (Exception ex)
            {
                this.logger.LogError(ex, $"Could not create npc intelligence for monster {monsterDefinition.Designation}, type name {monsterDefinition.IntelligenceTypeName}");
            }

            return(null);
        }
Beispiel #5
0
 /// <inheritdoc />
 public void DialogClosed(MonsterDefinition npc)
 {
     if (npc.NpcWindow == NpcWindow.ChaosMachine)
     {
         this.player.Connection?.SendCraftingDialogClosed075();
     }
 }
Beispiel #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Trap"/> class.
 /// </summary>
 /// <param name="spawnInfo">The spawn information.</param>
 /// <param name="stats">The stats.</param>
 /// <param name="map">The map on which this instance will spawn.</param>
 /// <param name="trapIntelligence">The trap intelligence.</param>
 public Trap(MonsterSpawnArea spawnInfo, MonsterDefinition stats, GameMap map, INpcIntelligence trapIntelligence)
     : base(spawnInfo, stats, map)
 {
     this.Attributes       = new TrapAttributeHolder(this);
     this.intelligence     = trapIntelligence;
     this.intelligence.Npc = this;
     this.intelligence.Start();
 }
Beispiel #7
0
 /// <inheritdoc/>
 public IEnumerable <Item> GetItemDrops(MonsterDefinition monster, int gainedExperience, Player player, out uint?droppedMoney)
 {
     droppedMoney = null;
     var character   = player.SelectedCharacter;
     var map         = player.CurrentMap.Definition;
     var questGroups = character.QuestStates?
                       .SelectMany(q => q.ActiveQuest?.RequiredItems
                                   .Where(i => i.DropItemGroup is { })
Beispiel #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Monster"/> class.
 /// </summary>
 /// <param name="spawnInfo">The spawn information.</param>
 /// <param name="stats">The stats.</param>
 /// <param name="id">The identifier.</param>
 /// <param name="map">The map on which this instance will spawn.</param>
 /// <param name="dropGenerator">The drop generator.</param>
 /// <param name="monsterIntelligence">The monster intelligence.</param>
 public Monster(MonsterSpawnArea spawnInfo, MonsterDefinition stats, ushort id, GameMap map, IDropGenerator dropGenerator, IMonsterIntelligence monsterIntelligence)
     : base(spawnInfo, stats, id, map)
 {
     this.dropGenerator        = dropGenerator;
     this.Attributes           = new MonsterAttributeHolder(this);
     this.walker               = new Walker(this);
     this.intelligence         = monsterIntelligence;
     this.intelligence.Monster = this;
     this.intelligence.Start();
 }
Beispiel #9
0
 /// <summary>
 /// Adds the attributes with their values to the <see cref="MonsterDefinition"/>.
 /// </summary>
 /// <param name="monsterDefinition">The monster definition.</param>
 /// <param name="attributesWithValues">The attributes with values.</param>
 /// <param name="context">The context.</param>
 /// <param name="gameConfiguration">The game configuration.</param>
 public static void AddAttributes(this MonsterDefinition monsterDefinition, IDictionary <AttributeDefinition, float> attributesWithValues, IContext context, GameConfiguration gameConfiguration)
 {
     foreach (var attributeWithValue in attributesWithValues)
     {
         var attribute = context.CreateNew <MonsterAttribute>();
         attribute.AttributeDefinition = attributeWithValue.Key.GetPersistent(gameConfiguration);
         attribute.Value = attributeWithValue.Value;
         monsterDefinition.Attributes.Add(attribute);
     }
 }
Beispiel #10
0
 /// <inheritdoc/>
 public IEnumerable <Item> GetItemDropsOrAddMoney(MonsterDefinition monster, int gainedExperience, Player player)
 {
     var character  = player.SelectedCharacter;
     var map        = player.CurrentMap.Definition;
     var dropGroups =
         CombineDropGroups(
             monster.DropItemGroups,
             character.DropItemGroups,
             map.DropItemGroups,
             character.QuestStates.SelectMany(q => q.ActiveQuest?.RequiredItems
                                              .Where(i => i.DropItemGroup is { })
Beispiel #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Monster"/> class.
 /// </summary>
 /// <param name="spawnInfo">The spawn information.</param>
 /// <param name="stats">The stats.</param>
 /// <param name="map">The map on which this instance will spawn.</param>
 /// <param name="dropGenerator">The drop generator.</param>
 /// <param name="monsterIntelligence">The monster intelligence.</param>
 public Monster(MonsterSpawnArea spawnInfo, MonsterDefinition stats, GameMap map, IDropGenerator dropGenerator, IMonsterIntelligence monsterIntelligence)
     : base(spawnInfo, stats, map)
 {
     this.dropGenerator        = dropGenerator;
     this.Attributes           = new MonsterAttributeHolder(this);
     this.MagicEffectList      = new MagicEffectsList(this);
     this.walker               = new Walker(this, () => this.StepDelay);
     this.intelligence         = monsterIntelligence;
     this.intelligence.Monster = this;
     this.intelligence.Start();
     this.Initialize();
 }
Beispiel #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Monster" /> class.
 /// </summary>
 /// <param name="spawnInfo">The spawn information.</param>
 /// <param name="stats">The stats.</param>
 /// <param name="map">The map on which this instance will spawn.</param>
 /// <param name="dropGenerator">The drop generator.</param>
 /// <param name="npcIntelligence">The monster intelligence.</param>
 /// <param name="plugInManager">The plug in manager.</param>
 public Monster(MonsterSpawnArea spawnInfo, MonsterDefinition stats, GameMap map, IDropGenerator dropGenerator, INpcIntelligence npcIntelligence, PlugInManager plugInManager)
     : base(spawnInfo, stats, map)
 {
     this.dropGenerator    = dropGenerator;
     this.Attributes       = new MonsterAttributeHolder(this);
     this.MagicEffectList  = new MagicEffectsList(this);
     this.walker           = new Walker(this, () => this.StepDelay);
     this.intelligence     = npcIntelligence;
     this.plugInManager    = plugInManager;
     this.intelligence.Npc = this;
     this.intelligence.Start();
 }
Beispiel #13
0
        /// <summary>
        /// Creates a new <see cref="MonsterSpawnArea"/> with the specified data.
        /// </summary>
        /// <param name="monsterDefinition">The monster definition.</param>
        /// <param name="x1">The x1 coordinate.</param>
        /// <param name="x2">The x2 coordinate.</param>
        /// <param name="y1">The y1 coordinate.</param>
        /// <param name="y2">The y2 coordinate.</param>
        /// <param name="quantity">The quantity.</param>
        /// <param name="direction">The direction.</param>
        /// <param name="spawnTrigger">The spawn trigger.</param>
        /// <returns>The created monster spawn area.</returns>
        protected MonsterSpawnArea CreateMonsterSpawn(MonsterDefinition monsterDefinition, byte x1, byte x2, byte y1, byte y2, short quantity = 1, Direction direction = Direction.Undefined, SpawnTrigger spawnTrigger = SpawnTrigger.Automatic)
        {
            var area = this.Context.CreateNew <MonsterSpawnArea>();

            area.GameMap           = this.mapDefinition;
            area.MonsterDefinition = monsterDefinition;
            area.Quantity          = quantity;
            area.Direction         = direction;
            area.SpawnTrigger      = spawnTrigger;
            area.X1 = x1;
            area.X2 = x2;
            area.Y1 = y1;
            area.Y2 = y2;
            return(area);
        }
Beispiel #14
0
        /// <inheritdoc/>
        public IEnumerable <Item> GetItemDropsOrAddMoney(MonsterDefinition monster, int gainedExperience, Player player)
        {
            var character  = player.SelectedCharacter;
            var map        = player.CurrentMap.Definition;
            var dropGroups =
                this.CombineDropGroups(monster.DropItemGroups, character.DropItemGroups, map.DropItemGroups)
                .OrderBy(group => group.Chance);

            for (int i = 0; i < monster.NumberOfMaximumItemDrops; i++)
            {
                var group = this.SelectRandomGroup(dropGroups);
                if (group == null)
                {
                    continue;
                }

                if (group.ItemType == SpecialItemType.Money)
                {
                    // Apply zen value: exp + 7
                    var money = gainedExperience + BaseMoneyDrop;
                    var party = player.Party;
                    if (party == null)
                    {
                        player.TryAddMoney((int)(money * player.Attributes[Stats.MoneyAmountRate]));
                    }
                    else
                    {
                        var players   = party.PartyList.OfType <Player>().Where(p => p.CurrentMap == player.CurrentMap && !p.IsAtSafezone()).ToList();
                        var moneyPart = money / players.Count;
                        players.ForEach(p => p.TryAddMoney((int)(moneyPart * p.Attributes[Stats.MoneyAmountRate])));
                    }
                }
                else
                {
                    var item = this.GetItemDrop(monster, group);
                    if (item != null)
                    {
                        yield return(item);
                    }
                }
            }
        }
Beispiel #15
0
 /// <inheritdoc />
 public IEnumerable <Item> GetItemDrops(MonsterDefinition monster, int gainedExperience, Player player, out uint?droppedMoney)
 {
     droppedMoney = null;
     return(Enumerable.Empty <Item>());
 }
Beispiel #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SoccerBall"/> class.
 /// </summary>
 /// <param name="spawnInfo">The spawn information.</param>
 /// <param name="stats">The stats.</param>
 /// <param name="map">The map on which this instance will spawn.</param>
 public SoccerBall(MonsterSpawnArea spawnInfo, MonsterDefinition stats, GameMap map)
     : base(spawnInfo, stats, map)
 {
     this.MagicEffectList = new MagicEffectsList(this);
     this.Attributes      = new AttributeSystem(Enumerable.Empty <IAttribute>(), Enumerable.Empty <IAttribute>(), Enumerable.Empty <AttributeRelationship>());
 }
 public static T SetMonsterDefinition <T>(this T entity, MonsterDefinition value)
     where T : MonsterKnowledgeDescription
 {
     entity.SetField("monsterDefinition", value);
     return(entity);
 }
        private static IDictionary <AttributeDefinition, float> GetStatAttributeOfMonster(MonsterDefinition monsterDef)
        {
            if (!MonsterStatAttributesCache.TryGetValue(monsterDef, out IDictionary <AttributeDefinition, float> result))
            {
                result = monsterDef.Attributes.ToDictionary(m => m.AttributeDefinition, m => m.Value);
                MonsterStatAttributesCache.Add(monsterDef, result);
            }

            return(result);
        }
Beispiel #19
0
 public static T SetMonsterDefinition <T>(this T entity, MonsterDefinition value)
     where T : GuiMonsterDefinition
 {
     entity.SetField("<MonsterDefinition>k__BackingField", value);
     return(entity);
 }
Beispiel #20
0
        /// <summary>
        /// Creates a new <see cref="MonsterSpawnArea"/> with the specified data.
        /// </summary>
        /// <param name="context">The persistence context.</param>
        /// <param name="map">The map.</param>
        /// <param name="monsterDefinition">The monster definition.</param>
        /// <param name="quantity">The quantity.</param>
        /// <param name="direction">The direction.</param>
        /// <param name="spawnTrigger">The spawn trigger.</param>
        /// <param name="x1">The x1 coordinate.</param>
        /// <param name="x2">The x2 coordinate.</param>
        /// <param name="y1">The y1 coordinate.</param>
        /// <param name="y2">The y2 coordinate.</param>
        /// <returns>The created monster spawn area.</returns>
        protected MonsterSpawnArea CreateMonsterSpawn(IContext context, GameMapDefinition map, MonsterDefinition monsterDefinition, short quantity, byte direction, SpawnTrigger spawnTrigger, byte x1, byte x2, byte y1, byte y2)
        {
            var area = context.CreateNew <MonsterSpawnArea>();

            area.GameMap           = map;
            area.MonsterDefinition = monsterDefinition;
            area.Quantity          = quantity;
            area.Direction         = (Direction)direction;
            area.SpawnTrigger      = spawnTrigger;
            area.X1 = x1;
            area.X2 = x2;
            area.Y1 = y1;
            area.Y2 = y2;
            return(area);
        }
 public static T SetBestiaryReference <T>(this T entity, MonsterDefinition value)
     where T : MonsterDefinition
 {
     entity.SetField("bestiaryReference", value);
     return(entity);
 }
Beispiel #22
0
 /// <summary>
 /// Creates a new <see cref="MonsterSpawnArea"/> with the specified data.
 /// </summary>
 /// <param name="monsterDefinition">The monster definition.</param>
 /// <param name="x">The x coordinate.</param>
 /// <param name="y">The y coordinate.</param>
 /// <param name="direction">The direction.</param>
 /// <param name="spawnTrigger">The spawn trigger.</param>
 /// <returns>The created monster spawn area.</returns>
 protected MonsterSpawnArea CreateMonsterSpawn(MonsterDefinition monsterDefinition, byte x, byte y, Direction direction = Direction.Undefined, SpawnTrigger spawnTrigger = SpawnTrigger.Automatic)
 => this.CreateMonsterSpawn(monsterDefinition, x, x, y, y, 1, direction, spawnTrigger);
Beispiel #23
0
 public static T SetMonsterDefinition <T>(this T entity, MonsterDefinition value)
     where T : RulesetCharacterMonster
 {
     entity.SetField("monsterDefinition", value);
     return(entity);
 }