Esempio n. 1
0
        public static Npc CreateNpc(SpawnTemplate spawnTemplate)
        {
            NpcTemplate npcTemplate = (Data.Data.NpcTemplates.ContainsKey(spawnTemplate.NpcId))
                ? Data.Data.NpcTemplates[spawnTemplate.NpcId]
                : new NpcTemplate();

            var npc = new Npc
            {
                NpcId         = spawnTemplate.NpcId,
                SpawnTemplate = spawnTemplate,
                NpcTemplate   = npcTemplate,

                Position = new WorldPosition
                {
                    MapId = spawnTemplate.MapId,
                    X     = spawnTemplate.X,
                    Y     = spawnTemplate.Y,
                    Z     = spawnTemplate.Z,
                },
            };

            npc.BindPoint = npc.Position.Clone();

            npc.GameStats = CreatureLogic.InitGameStats(npc);
            CreatureLogic.UpdateCreatureStats(npc);

            AiLogic.InitAi(npc);

            return(npc);
        }
Esempio n. 2
0
        public static Npc CreateNpc(SpawnTemplate spawnTemplate)
        {
            var npc = new Npc
            {
                NpcId         = spawnTemplate.NpcId,
                SpawnTemplate = spawnTemplate,
                NpcTemplate   = Data.Data.NpcTemplates[spawnTemplate.Type][spawnTemplate.NpcId],

                Position = new WorldPosition
                {
                    MapId = spawnTemplate.MapId,
                    X     = spawnTemplate.X,
                    Y     = spawnTemplate.Y,
                    Z     =
                        spawnTemplate.Z +
                        ((spawnTemplate.FullId == 6301151 ||
                          spawnTemplate.FullId == 6301152 ||
                          spawnTemplate.FullId == 6301153)
                             ? 0
                             : 25),
                    Heading = spawnTemplate.Heading,
                }
            };

            npc.BindPoint = npc.Position.Clone();

            npc.GameStats = CreatureLogic.InitGameStats(npc);
            CreatureLogic.UpdateCreatureStats(npc);

            AiLogic.InitAi(npc);

            return(npc);
        }
Esempio n. 3
0
    public void Play()
    {
        AiLogic ai = new AiLogic();

        PlayerType[] players = new PlayerType[2];
        players[0] = playerOne.value == 0 ? PlayerType.Human : PlayerType.AI;
        players[1] = playerTwo.value == 0 ? PlayerType.Human : PlayerType.AI;


        Callbacks callbacks = new Callbacks();

        callbacks.humanTurnStartCallback = OnHumansTurnStart;
        callbacks.gameVictoryCallback    = OnGameWin;
        callbacks.moveCallback           = OnMove;
        callbacks.gameTieCallback        = OnGameTie;
        callbacks.gameFinishedCallback   = OnGameDone;
        try {
            game = new Game(ai, callbacks, boardAssembler.GetColumns(), boardAssembler.GetRows(), winNum, players);
            showCustom.SetActiveElements(0);
            ToggleUI(false);
        } catch {
            errorText.gameObject.SetActive(true);
            errorText.text = "Board is Not Legal (Check to make sure it is playable!)";
        }
    }
Esempio n. 4
0
        private void ProcessAttack(Creature creature, UseSkillArgs args, int time)
        {
            try
            {
                Creature target = creature.Target;

                if (target == null || creature.LifeStats.IsDead())
                {
                    return;
                }

                if (!target.LifeStats.IsDead())
                {
                    creature.Attack = new Attack(creature,
                                                 args,
                                                 () => GlobalLogic.AttackStageEnd(creature),
                                                 () => GlobalLogic.AttackFinished(creature));

                    int damage = SeUtils.CalculateDefaultAttackDamage(creature, target, creature.GameStats.Attack);

                    Player player = creature as Player;
                    if (player != null)
                    {
                        VisibleService.Send(player, new SpAttack(player, player.Attack));
                    }

                    Npc npc = creature as Npc;
                    if (npc != null)
                    {
                        VisibleService.Send(npc, new SpNpcAttack(npc, npc.Attack));
                    }

                    target.LifeStats.MinusHp(damage);

                    AiLogic.OnAttack(creature, target);
                    AiLogic.OnAttacked(target, creature, damage);

                    if (target is Player)
                    {
                        (target as Player).LifeStats.PlusSp(damage);
                    }

                    new DelayedAction(creature
                                      .Attack
                                      .NextStage, time);

                    return;
                }

                new DelayedAction(creature
                                  .Attack
                                  .Finish, time);
            }
            catch (Exception ex)
            {
                Log.ErrorException("ProcessAttack:", ex);
            }
        }
Esempio n. 5
0
        public void InitPlayer(Player player)
        {
            player.GameStats = CreatureLogic.InitGameStats(player);
            CreatureLogic.UpdateCreatureStats(player);

            AiLogic.InitAi(player);

            PlayersOnline.Add(player);
        }
Esempio n. 6
0
 public Game(AiLogic ai, uint length, uint height, uint winLength, GameType gameType)
 {
     if (gameType == GameType.TwoPlayer)
     {
         Setup(ai, new Callbacks(), length, height, winLength, new PlayerType[] { PlayerType.Human, PlayerType.Human });
     }
     else if (gameType == GameType.SinglePlayer)
     {
         Setup(ai, new Callbacks(), length, height, winLength, new PlayerType[] { PlayerType.Human, PlayerType.AI });
     }
     else if (gameType == GameType.SinglePlayerMoveSecond)
     {
         Setup(ai, new Callbacks(), length, height, winLength, new PlayerType[] { PlayerType.AI, PlayerType.Human });
     }
     throw new System.Exception("Fell threw all gameType checks (This should be impossible)!");
 }
Esempio n. 7
0
 public Game(AiLogic ai, Callbacks callbacks, GameType gameType)
 {
     if (gameType == GameType.TwoPlayer)
     {
         Setup(ai, callbacks, 7, 6, 4, new PlayerType[] { PlayerType.Human, PlayerType.Human });
     }
     else if (gameType == GameType.SinglePlayer)
     {
         Setup(ai, callbacks, 7, 6, 4, new PlayerType[] { PlayerType.Human, PlayerType.AI });
     }
     else if (gameType == GameType.SinglePlayerMoveSecond)
     {
         Setup(ai, callbacks, 7, 6, 4, new PlayerType[] { PlayerType.AI, PlayerType.Human });
     }
     throw new System.Exception("Fell threw all gameType checks (This should be impossible)!");
 }
Esempio n. 8
0
        public Gather CreateGather(GSpawnTemplate gSpawn)
        {
            var gather = new Gather
            {
                Id       = gSpawn.CollectionId,
                Position = new WorldPosition
                {
                    MapId = gSpawn.WorldPosition.MapId,
                    X     = gSpawn.WorldPosition.X,
                    Y     = gSpawn.WorldPosition.Y,
                    Z     = gSpawn.WorldPosition.Z + 10,
                },
                CurrentGatherCounter = new Random().Next(1, 3), //todo gather counter
            };

            AiLogic.InitAi(gather);

            return(gather);
        }
Esempio n. 9
0
        private void ProcessSkill(Creature creature, List <UseSkillArgs> argsList, Skill skill)
        {
            creature.Attack = new Attack(creature,
                                         argsList[0],
                                         () => GlobalLogic.AttackStageEnd(creature),
                                         () => GlobalLogic.AttackFinished(creature));

            VisibleService.Send(creature, new SpAttack(creature, creature.Attack));

            VisibleService.Send(creature, new SpAttackDestination(creature, creature.Attack));

            ProcessStages(creature, skill);

            ProcessMove(creature, skill);

            AiLogic.OnUseSkill(creature, skill);

            ProcessTargets(creature, skill);
        }
Esempio n. 10
0
        public AiSelectSkillResultSerializableData SelectSkill(int uniqId)
        {
            BattlerSerializable battler = BattlerDictionary.GetBattlerByUniqId(uniqId);
            //スキルを無造作に選ぶ、アタックの重みは少ない
            var choice = new WeightChoice <string>();

            foreach (var x in battler.skills)
            {
                var _skill = SkillsDicionary.GetSkillById(x);
                if (_skill.skillId == SkillIds.ATTACK)
                {
                    choice.Add(SkillWeights.VERY_LOW, x);
                }
                else if (battler.parameter.mp >= _skill.mp)
                {
                    choice.Add(SkillWeights.NORMAL, x);
                }
            }

            AiSelectSkillResultSerializableData result = new AiSelectSkillResultSerializableData();
            var skill = SkillsDicionary.GetSkillById(choice.ChoiceOne());

            if (battler.parameter.mp >= skill.mp)
            {
                switch (skill.target)
                {
                case SkillConsts.ENEMY:
                case SkillConsts.MEMBER:
                    result.TargetUniqIds.Add(
                        AiLogic.ChoiceBattlerByHostile(BattleDictionary.GetAliveRivalBattlers(battler.battlerType)));
                    break;

                case SkillConsts.ALL_ENEMY:
                case SkillConsts.ALL_MEMBER:
                    result.TargetUniqIds = BattleDictionary.GetRivalUniqIds(battler.battlerType);
                    break;
                }
                result.SkillId = skill.skillId;
            }

            return(result);
        }
Esempio n. 11
0
        public override void Process(IConnection connection, string[] msg)
        {
            try
            {
                Player   player   = connection.Player;
                Creature creature = player.Target;
                if (creature != null)
                {
                    creature.LifeStats.MinusHp(creature.MaxHp + 1);

                    AiLogic.OnAttack(player, creature);
                    AiLogic.OnAttacked(creature, player, creature.MaxHp + 1);
                }
            }
            catch (Exception e)
            {
                Print(connection, "Wrong syntax!");
                Print(connection, "Syntax: @kill");
                Log.Warn(e.ToString());
            }
        }
Esempio n. 12
0
        public void InitPlayer(Player player, bool isProlog)
        {
            player.PlayerLevel = 1;
            while ((player.PlayerLevel + 1) != Data.Data.PlayerExperience.Count - 1 && player.PlayerExp >= Data.Data.PlayerExperience[player.PlayerLevel])
            {
                player.PlayerLevel++;
            }

            if (player.Skills.Count == 0)
            {
                for (int i = 0; i < Data.Data.DefaultSkillSets[player.TemplateId].SkillSet.Count; i++)
                {
                    player.Skills.Add(Data.Data.DefaultSkillSets[player.TemplateId].SkillSet[i]);
                }
            }

            player.GameStats = CreatureLogic.InitGameStats(player);
            CreatureLogic.UpdateCreatureStats(player);
            AiLogic.InitAi(player);
            PlayersOnline.Add(player);
        }
Esempio n. 13
0
 void Setup(AiLogic ai, Callbacks callbacks, uint length, uint height, uint winLength, PlayerType[] players)
 {
     if (winLength > length && winLength > height)
     {
         throw new System.Exception("Win length is greater than board length and height!");
     }
     else if (winLength < 2)
     {
         throw new System.Exception("Win length is less than two!");
     }
     else if (players.Length < 2)
     {
         throw new System.Exception("There are less than two players!");
     }
     else if (ai == null)
     {
         throw new System.Exception("AI is null!");
     }
     else if (players == null)
     {
         throw new System.Exception("Players is null!");
     }
     this.ai        = ai;
     this.length    = length;
     this.height    = height;
     this.winLength = winLength;
     this.players   = players;
     currentPlayer  = 0;
     board          = new uint?[length, height];
     gameState      = GameState.InProgress;
     this.callbacks = callbacks;
     if (callbacks.humanTurnStartCallback != null)
     {
         callbacks.humanTurnStartCallback(currentPlayer);
     }
 }
Esempio n. 14
0
        private async void ProcessArea(Creature creature, Skill skill, Targeting targeting, TargetingArea area,
                                       Projectile projectile = null)
        {
            try
            {
                bool isProjectileSkill = skill.Type == SkillType.Projectile || skill.Type == SkillType.Userslug;

                int skillId = creature.Attack.Args.SkillId;
                if (isProjectileSkill)
                {
                    skillId += 20;
                }

                if (targeting.Time > 0)
                {
                    await Task.Delay((int)(targeting.Time / skill.TimeRate));
                }
                int elapsed = targeting.Time;

                Player player = creature as Player;

                do
                {
                    try
                    {
                        if (creature.LifeStats.IsDead())
                        {
                            return;
                        }

                        if (area.DropItem != null)
                        {
                            creature.Instance.AddDrop(new Item
                            {
                                Owner = player,

                                ItemId   = (int)area.DropItem,
                                Count    = 1,
                                Position = Geom.ForwardPosition(creature.Position, 40),
                                Instance = player.Instance,
                            });
                        }

                        Point3D center =
                            projectile != null
                                ? projectile.Position.ToPoint3D()
                                : Geom.GetNormal(creature.Position.Heading)
                            .Multiple(area.OffsetDistance)
                            .Add(creature.Position);

                        int count = 0;

                        List <Creature> targets =
                            creature.Attack.Args.Targets.Count > 0
                                ? creature.Attack.Args.Targets
                                : VisibleService.FindTargets(creature,
                                                             center,
                                                             projectile != null
                                                                 ? projectile.AttackDistance
                                                                 : area.MaxRadius,
                                                             area.Type);

                        foreach (Creature target in targets)
                        {
                            if (target != creature && //Ignore checks for self-target
                                !isProjectileSkill &&
                                !creature.Attack.Args.IsItemSkill)
                            {
                                if (center.DistanceTo(target.Position) < area.MinRadius - 40)
                                {
                                    continue;
                                }

                                if (center.DistanceTo(target.Position) > area.MaxRadius)
                                {
                                    continue;
                                }

                                short diff = Geom.GetAngleDiff(creature.Attack.Args.StartPosition.Heading,
                                                               Geom.GetHeading(center, target.Position));

                                //diff from 0 to 180
                                //area.RangeAngel from 0 to 360
                                if (diff * 2 > (creature.Attack.Args.IsTargetAttack ? 90 : Math.Abs(area.RangeAngle) + 10))
                                {
                                    continue;
                                }
                            }

                            if (skill.TotalAtk > 0)
                            {
                                int damage = SeUtils.CalculateDamage(creature, target, skill.TotalAtk * area.Effect.Atk);

                                AttackResult result
                                    = new AttackResult
                                    {
                                    AttackType = AttackType.Normal,
                                    AttackUid  = creature.Attack.UID,
                                    Damage     = damage,
                                    Target     = target,
                                    };

                                result.AngleDif = Geom.GetAngleDiff(creature.Attack.Args.StartPosition.Heading, result.Target.Position.Heading);
                                SeUtils.UpdateAttackResult(creature, result);

                                if (result.AttackType == AttackType.Block)
                                {
                                    VisibleService.Send(target, new SpAttackShowBlock(target, skillId));
                                }

                                VisibleService.Send(target, new SpAttackResult(creature, skillId, result));

                                AiLogic.OnAttack(creature, target);
                                AiLogic.OnAttacked(target, creature, result.Damage);

                                if (target is Player && ((Player)target).Duel != null && player != null &&
                                    ((Player)target).Duel.Equals(player.Duel) &&
                                    target.LifeStats.GetHpDiffResult(damage) < 1)
                                {
                                    DuelService.FinishDuel(player);
                                }
                                else
                                {
                                    CreatureLogic.HpChanged(target, target.LifeStats.MinusHp(result.Damage));
                                }
                            }

                            if (area.Effect.HpDiff > 0)
                            {
                                AttackResult result = new AttackResult {
                                    HpDiff = area.Effect.HpDiff, Target = target
                                };

                                PassivityProcessor.OnHeal(player, result);
                                if (target is Player)
                                {
                                    PassivityProcessor.OnHealed((Player)target, result);
                                }

                                CreatureLogic.HpChanged(target, target.LifeStats.PlusHp(result.HpDiff),
                                                        creature);
                            }

                            if (area.Effect.MpDiff > 0)
                            {
                                CreatureLogic.MpChanged(target, target.LifeStats.PlusMp(area.Effect.MpDiff), creature);
                            }

                            if (area.Effect.AbnormalityOnCommon != null)
                            {
                                for (int i = 0; i < area.Effect.AbnormalityOnCommon.Count; i++)
                                {
                                    AbnormalityProcessor.AddAbnormality(target, area.Effect.AbnormalityOnCommon[i],
                                                                        creature);
                                }
                            }
                            if (player != null)
                            {
                                DuelService.ProcessDamage(player);

                                //MP regen on combo skill
                                if (skill.Id / 10000 == 1 && player.GameStats.CombatMpRegen > 0)
                                {
                                    CreatureLogic.MpChanged(player, player.LifeStats.PlusMp(
                                                                player.MaxMp * player.GameStats.CombatMpRegen / 200));
                                }
                            }

                            if (++count == area.MaxCount)
                            {
                                break;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteLine(LogState.Exception, "SkillEngine: ProcessAreaExc: " + ex);
                    }

                    if (targeting.Interval > 0)
                    {
                        await Task.Delay((int)(targeting.Interval / skill.TimeRate));

                        elapsed += targeting.Interval;
                    }
                } while (targeting.Interval > 0 && elapsed < targeting.Until);
            }
            catch (Exception ex)
            {
                Logger.WriteLine(LogState.Exception, "SkillEngine: ProcessArea: " + ex);
            }
        }
Esempio n. 15
0
        private void ProcessSkill(Creature creature, UseSkillArgs args, Skill skill, Projectile projectile = null)
        {
            bool isProjectileSkill = skill.Type == SkillType.Projectile || skill.Type == SkillType.Userslug;

            if (!isProjectileSkill)
            {
                if (skill.ChargingStageList == null || skill.ChargingStageList.ChargeStageList.Count == 0)
                {
                    if (skill.Precondition.Cost.Hp > 0)
                    {
                        CreatureLogic.HpChanged(creature, creature.LifeStats.MinusHp(skill.Precondition.Cost.Hp));
                    }

                    if (skill.Precondition.Cost.Mp > 0)
                    {
                        CreatureLogic.MpChanged(creature, creature.LifeStats.MinusMp(skill.Precondition.Cost.Mp));
                    }
                }

                if (!args.IsDelaySkill || args.IsDelayStart)
                {
                    if (args.TargetPosition.IsNull())
                    {
                        double angle = args.StartPosition.Heading * Math.PI / 32768;

                        args.StartPosition.CopyTo(args.TargetPosition);

                        args.TargetPosition.X += 100 * (float)Math.Cos(angle);
                        args.TargetPosition.Y += 100 * (float)Math.Sin(angle);
                    }

                    // ReSharper disable ImplicitlyCapturedClosure
                    creature.Attack = new Attack(creature,
                                                 args,
                                                 () => GlobalLogic.AttackStageEnd(creature),
                                                 () => GlobalLogic.AttackFinished(creature));
                    // ReSharper restore ImplicitlyCapturedClosure

                    VisibleService.Send(creature, new SpAttack(creature, creature.Attack));

                    VisibleService.Send(creature, new SpAttackDestination(creature, creature.Attack));

                    if (!args.IsDelaySkill)
                    {
                        ProcessStages(creature, skill);
                    }
                    else
                    {
                        Player player = creature as Player;
                        if (player != null && skill.BaseId == 20100 &&
                            (player.PlayerData.Class == PlayerClass.Berserker ||
                             player.PlayerData.Class == PlayerClass.Lancer))
                        {
                            player.EffectsImpact.ResetChanges(player); //Set IsBlockFrontAttacks
                        }
                    }

                    ProcessMove(creature, skill);
                }
            }
            else
            {
                creature.Attack.Args.IsTargetAttack = args.IsTargetAttack;
                creature.Attack.Args.Targets        = args.Targets;

                ProcessProjectileTargets(creature, skill, projectile);
            }

            AiLogic.OnUseSkill(creature, skill);

            if (skill.ChargingStageList != null)
            {
                if (args.IsDelayStart)
                {
                    int uid = creature.Attack.UID;

                    ThreadPool.QueueUserWorkItem(
                        o =>
                    {
                        Thread.Sleep(750);

                        for (int i = 1; i < skill.ChargingStageList.ChargeStageList.Count; i++)
                        {
                            if (creature.Attack.UID != uid)
                            {
                                return;
                            }

                            creature.Attack.NextStage();

                            if (i != 3)
                            {
                                Thread.Sleep(750);
                            }
                        }
                    });
                }
            }
            else
            {
                ProcessTargets(creature, skill);
            }
        }
Esempio n. 16
0
 public Game(AiLogic ai, Callbacks callbacks, uint length, uint height, uint winLength, PlayerType[] players)
 {
     Setup(ai, callbacks, length, height, winLength, players);
 }
Esempio n. 17
0
        private void ProcessSkill(Creature creature, UseSkillArgs args, Skill skill, int time)
        {
            try
            {
                Player   player = creature as Player;
                Creature target = creature.Target;

                if (target == null || creature.LifeStats.IsDead())
                {
                    return;
                }

                if (creature.LifeStats.Mp < skill.ManaCost)
                {
                    if (player != null)
                    {
                        new SpPlayerSetSpell(args.SkillId, 2, 0).Send(player);
                    }
                }

                if (!target.LifeStats.IsDead())
                {
                    creature.Attack = new Attack(creature,
                                                 args,
                                                 () => GlobalLogic.AttackStageEnd(creature),
                                                 () => GlobalLogic.AttackFinished(creature));

                    int damage = SeUtils.CalculateDefaultAttackDamage(creature, target, creature.GameStats.Attack);

                    if (player != null)
                    {
                        VisibleService.Send(player, new SpAttack(player, player.Attack));
                    }

                    Npc npc = creature as Npc;
                    if (npc != null)
                    {
                        VisibleService.Send(npc, new SpNpcAttack(npc, npc.Attack));
                    }

                    switch (skill.Type)
                    {
                    case 2:

                        break;

                    case 3:

                        break;

                    default:
                        creature.LifeStats.MinusMp(skill.ManaCost);
                        break;
                    }

                    target.LifeStats.MinusHp(damage);

                    AiLogic.OnAttack(creature, target);
                    AiLogic.OnAttacked(target, creature, damage);

                    if (target is Player)
                    {
                        (target as Player).LifeStats.PlusSp(damage);
                    }

                    new DelayedAction(creature
                                      .Attack
                                      .NextStage, time);

                    return;
                }
            }
            catch (Exception ex)
            {
                Log.ErrorException("ProcessSkill:", ex);
            }
        }