예제 #1
0
 public void startFight(GameNpc myNpc, GameNpc enemyNpc, FightEvent fightEvent)
 {
     this.myNpc      = myNpc;
     this.enemyNpc   = enemyNpc;
     this.fightEvent = fightEvent;
     runEvent();
 }
예제 #2
0
    private static void loadSkill(GameNpc npc, int id)
    {
        string sId = id.ToString();
        int    skillId;

        for (int i = 0; i < skillCount; i++)
        {
            skillId = PlayerPrefs.GetInt(sId + "_Skill" + "_" + (i + 1));
            FightEvent temp = null;
            //找到技能
            if (skillId != 0)
            {
                switch (skillId)
                {
                case 1:
                    npc.gameObject.AddComponent <FightNormalAttack>();
                    temp = npc.gameObject.GetComponent <FightNormalAttack>();
                    break;
                }
                if (temp != null)
                {
                    temp.skillName    = PlayerPrefs.GetString(sId + "_Skill" + "_" + skillId + "_name");
                    temp.skillText    = PlayerPrefs.GetString(sId + "_Skill" + "_" + skillId + "_text");
                    temp.skillLvl     = PlayerPrefs.GetInt(sId + "_Skill" + "_" + skillId + "_lvl");
                    temp.skillMaxLvl  = PlayerPrefs.GetInt(sId + "_Skill" + "_" + skillId + "_maxLvl");
                    temp.skillExp     = PlayerPrefs.GetFloat(sId + "_Skill" + "_" + skillId + "_exp");
                    temp.skillMaxExp  = PlayerPrefs.GetFloat(sId + "_Skill" + "_" + skillId + "_maxExp");
                    temp.skillHurtAmp = PlayerPrefs.GetFloat(sId + "_Skill" + "_" + skillId + "_hurtAmp");
                    temp.skillHurtAdd = PlayerPrefs.GetFloat(sId + "_Skill" + "_" + skillId + "_hurtAdd");
                }
            }
        }
    }
예제 #3
0
            private void ProcessFightEventsUpdateViews(List <FightEvent> fightEvents, FightStatus activeFightStatus)
            {
                int        num        = 1;
                int        count      = fightEvents.Count;
                FightEvent fightEvent = fightEvents[0];

                s_eventGroupBuffer.Add(fightEvent);
                while (num < count && fightEvent.IsInvisible())
                {
                    FightEvent fightEvent2 = fightEvents[num];
                    num++;
                    s_eventGroupBuffer.Add(fightEvent2);
                    fightEvent = fightEvent2;
                }
                while (num < count)
                {
                    FightEvent fightEvent3 = fightEvents[num];
                    num++;
                    if (!fightEvent3.IsInvisible() && !fightEvent3.CanBeGroupedWith(fightEvent))
                    {
                        SendFightEventGroupToExecution(activeFightStatus);
                    }
                    s_eventGroupBuffer.Add(fightEvent3);
                    fightEvent = fightEvent3;
                }
                SendFightEventGroupToExecution(activeFightStatus);
            }
예제 #4
0
        private static bool Dodge(DMEnv env, Investigator inv)
        {
            FightEvent fight = inv.PeekNextFight(env.Sce, out Investigator source, out Item oppositeWeapon);

            if (oppositeWeapon.Type == "射击")
            {
                env.Next = oppositeWeapon + "是射击武器,仅肉搏或投掷武器可闪避!";
                return(false);
            }

            if (!inv.Check("闪避", out CheckResult result, out string str))
            {
                env.Next = str;
                return(false);
            }
            inv.Fights.Dequeue();

            env.AppendLine(str);
            env.Save();
            if (result.succeed && result.type <= fight.ResultType)
            {
                env.Append($"躲开了{fight}!");
                return(true);
            }
            else
            {
                env.AppendLine($"受到了{fight}");
                CalculateDamage(env, source, inv, fight.WeaponName);
                return(false);
            }
        }
예제 #5
0
        private static void CommitFight(DMEnv env, Investigator source, Investigator target, string weaponName, int points, int resultType)
        {
            FightEvent fight = new FightEvent(source.Name, target.Name, weaponName, points, resultType);

            target.Fights.Enqueue(fight);
            env.Save();
            env.Next = target.Name + "即将受到" + fight;
        }
예제 #6
0
 public void startFight(GameNpc myNpc, GameNpc enemyNpc, FightEvent fightEvent, float maxTime)
 {
     this.myNpc      = myNpc;
     this.enemyNpc   = enemyNpc;
     this.fightEvent = fightEvent;
     this.maxTime    = maxTime;
     runEvent();
 }
예제 #7
0
 public void startFight(GameNpc myNpc, GameNpc enemyNpc)
 {
     this.myNpc      = myNpc;
     this.enemyNpc   = enemyNpc;
     this.fightEvent = null;
     this.maxTime    = 0;
     runEvent();
 }
예제 #8
0
 private static void Skip(DMEnv env, Investigator inv)
 {
     if (inv.Fights.Count > 0)
     {
         FightEvent fight = inv.Fights.Dequeue();
         env.Save();
         env.Next = $"已经跳过了来自{fight.SourceName}的打斗";
     }
     env.Next = "没有需要跳过打斗";
 }
예제 #9
0
            private void SendFightEventGroupToExecution(FightStatus activeFightStatus)
            {
                int count = s_eventGroupBuffer.Count;

                if (count == 1)
                {
                    FightEvent fightEvent = s_eventGroupBuffer[0];
                    try
                    {
                        if (fightEvent.SynchronizeExecution())
                        {
                            Execute(SetupSynchronizationBarrier());
                            IEnumerator enumerator = fightEvent.UpdateView(activeFightStatus);
                            if (enumerator != null)
                            {
                                Execute(enumerator);
                            }
                            Execute(ReleaseSynchronizationBarrier());
                        }
                        else
                        {
                            IEnumerator enumerator2 = fightEvent.UpdateView(activeFightStatus);
                            if (enumerator2 != null)
                            {
                                Execute(enumerator2);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error($"Exception occured while event {fightEvent.eventType} #{fightEvent.eventId} updated fight view.", 255, "C:\\BuildAgents\\AgentB\\work\\cub_client_win64_develop\\client\\DofusCube.Unity\\Assets\\Core\\Code\\Fight\\FightLogicExecutor.Instance.cs");
                        Debug.LogException(ex);
                    }
                }
                else
                {
                    IEnumerator[] array = new IEnumerator[count];
                    for (int i = 0; i < count; i++)
                    {
                        FightEvent fightEvent2 = s_eventGroupBuffer[i];
                        try
                        {
                            array[i] = fightEvent2.UpdateView(activeFightStatus);
                        }
                        catch (Exception ex2)
                        {
                            Log.Error($"Exception occured while event {fightEvent2.eventType} #{fightEvent2.eventId} updated fight view.", 273, "C:\\BuildAgents\\AgentB\\work\\cub_client_win64_develop\\client\\DofusCube.Unity\\Assets\\Core\\Code\\Fight\\FightLogicExecutor.Instance.cs");
                            Debug.LogException(ex2);
                        }
                    }
                    IEnumerator action = EnumeratorUtility.ParallelRecursiveImmediateExecution(array);
                    Execute(action);
                }
                s_eventGroupBuffer.Clear();
            }
예제 #10
0
        private static void GiveUp(DMEnv env, Investigator inv)
        {
            if (inv.Fights.Count == 0)
            {
                env.Next = "未找到打斗事件";
            }
            FightEvent fight = inv.Fights.Dequeue();

            if (!env.Sce.TryGetInvestigator(fight.SourceName, out Investigator source))
            {
                env.Next = $"未找到打斗来源:{fight.SourceName}";
            }

            CalculateDamage(env, source, inv, fight.WeaponName);
        }
예제 #11
0
        public void UpdateObject(float deltaTime)
        {
            FighterState state = GetFrame();

            if (state != lastState)
            {
                if (state.wwiseEvent && controller != null)
                {
                    AkSoundEngine.PostEvent(state.wwiseEventName, controller);
                }
                //Launch Events
                foreach (Event e in state.events)
                {
                    if (FightEvent != null)
                    {
                        Debug.Log("Invoking");
                        FightEvent.Invoke(e);
                    }
                }
            }

            lastState   = state;
            parryTimer += deltaTime;
            guard      -= guardDecrease * deltaTime;
            stun       -= stunDecrease * deltaTime;
            if (guard < 0)
            {
                guard = 0.0f;
            }
            if (stun < 0)
            {
                stun = 0.0f;
            }
            if (bFallen)
            {
                fallTimer += deltaTime;
                if (fallTimer >= fallTime)
                {
                    SetMove(GetUp);
                    bFallen = false;
                }
            }
        }
예제 #12
0
    // returns fight event animation duration
    private float playEventAnimation(FightEvent fightEvent)
    {
        //Debug.Log(fightEvent.eventType.ToString());
        switch (fightEvent.eventType)
        {
        case FightEventType.JOIN_FIGHT:
            return(playJoinFightAnimations(fightEvent.targets));

        case FightEventType.LEAVE_FIGHT:
            return(playLeaveFightAnimations());

        case FightEventType.JOIN_COMBAT:
            return(playJoinCombatAnimations(fightEvent.targets));

        case FightEventType.DEATH:
            return(playDeathAnimations(fightEvent.targets));
        }
        return(0);
    }
예제 #13
0
        private static bool FightBack(DMEnv env, Investigator target, string weaponName)
        {
            Item       selfWeapon = target.GetItem(weaponName);
            FightEvent fight      = target.PeekNextFight(env.Sce, out Investigator source, out Item oppositeWeapon);

            if (oppositeWeapon.Type != "肉搏")
            {
                env.Next = oppositeWeapon + "不是肉搏武器,仅肉搏可反击!";
                return(false);
            }

            if (!target.Check(oppositeWeapon.SkillName, out CheckResult result, out string str))
            {
                env.Next = str;
                return(false);
            }

            target.Fights.Dequeue();

            env.AppendLine(str);
            if (result.succeed && result.type < fight.ResultType)
            {
                int mulfunctionCheckResult = Dice.Roll(100);
                if (mulfunctionCheckResult > selfWeapon.Mulfunction)
                {
                    env.Append($"{target.Name}的{selfWeapon.Name}{(selfWeapon.Type == "射击" ? "炸膛" : "坏掉")}了!({mulfunctionCheckResult} > {selfWeapon.Mulfunction})");
                    return(false);
                }
                env.Append($"反击了{fight}!");
                CalculateDamage(env, target, source, weaponName);
            }
            else
            {
                env.Append($"受到了{fight}!");
                CalculateDamage(env, source, target, fight.WeaponName);
            }
            return(true);
        }
예제 #14
0
    /*
     * private int countTotalHeroHealth(List<Hero> heroes)
     * {
     * int health = 0;
     * foreach (Hero hero in heroes)
     * {
     *  health += hero.currenthp;
     * }
     * return health;
     * }
     *
     * private int countTotalHeroDamage(List<Hero> heroes)
     * {
     * int damage = 0;
     * foreach (Hero hero in heroes)
     * {
     *  damage += hero.damage;
     * }
     * return damage;
     * }
     *
     * private int countTotalHeroHealing(List<Hero> heroes)
     * {
     * int healing = 0;
     * foreach (Hero hero in heroes)
     * {
     *  healing += hero.healing;
     * }
     * return healing;
     * }*/

    private void animateFight(MatchState matchState)
    {
        FightEvent join = new FightEvent();

        join.eventType = FightEventType.JOIN_FIGHT;
        FightEventTarget target;

        FightEvent leave = new FightEvent();

        leave.eventType = FightEventType.LEAVE_FIGHT;

        foreach (Hero hero in matchState.fightAllHeroes)
        {
            target            = new FightEventTarget();
            target.targetType = FightEventTargetType.HERO;
            target.id         = hero.id;
            join.targets.Add(target);
            leave.targets.Add(target);
        }

        FightEvent die = new FightEvent();

        die.eventType = FightEventType.DEATH;

        foreach (Hero hero in matchState.fightDeadHeroes)
        {
            target            = new FightEventTarget();
            target.targetType = FightEventTargetType.HERO;
            target.id         = hero.id;
            die.targets.Add(target);
        }

        fightEvents.Add(join);
        fightEvents.Add(die);
        fightEvents.Add(leave);

        FightAnimatorScript.Instance.PlayFight(fightEvents);
    }
예제 #15
0
        /// <summary>
        /// 获取下一个打斗事件,以下情况均会抛出异常:
        /// - 打斗事件队列为空
        /// - 打斗的对象不存在
        /// - 打斗的对象的武器不存在
        /// 要注意,这并不会将该事件撤出队列!
        /// </summary>
        /// <param name="sce">用来检查的存档</param>
        /// <param name="oppositeInv">对手实例</param>
        /// <param name="oppositeWeapon">对手武器</param>
        /// <returns>合法的下一个打斗事件</returns>
        public FightEvent PeekNextFight(Scenario sce, out Investigator oppositeInv, out Item oppositeWeapon)
        {
            if (Fights.Count == 0)
            {
                throw new DiceException("未找到打斗事件");
            }
            FightEvent fight = Fights.Peek();

            if (!sce.TryGetInvestigator(fight.SourceName, out oppositeInv))
            {
                throw new DiceException($"未找到打斗来源:{fight.SourceName}");
            }

            if (fight.WeaponName == null)
            {
                oppositeWeapon = new Item("身体");
            }
            else if (!oppositeInv.Inventory.TryGetValue(fight.WeaponName, out oppositeWeapon))
            {
                throw new DiceException($"未找到{oppositeInv.Name}的{fight.WeaponName}");
            }
            return(fight);
        }
예제 #16
0
            private void ProcessFightEventsUpdateStatus(List <FightEvent> fightEvents, FightStatus activeFightStatus)
            {
                m_dirtyEntitiesCounter = 0;
                m_dirtySpellsCounters.ResetAll();
                int count = fightEvents.Count;

                for (int i = 0; i < count; i++)
                {
                    FightEvent fightEvent = fightEvents[i];
                    long?      num        = fightEvent.parentEventId;
                    if (num.HasValue)
                    {
                        s_eventHierarchyBuffer[num.Value].AddChildEvent(fightEvent);
                    }
                    try
                    {
                        fightEvent.UpdateStatus(activeFightStatus);
                    }
                    catch (Exception ex)
                    {
                        Log.Error($"Exception occured while event {fightEvent.eventType} #{fightEvent.eventId} updated fight status.", 144, "C:\\BuildAgents\\AgentB\\work\\cub_client_win64_develop\\client\\DofusCube.Unity\\Assets\\Core\\Code\\Fight\\FightLogicExecutor.Instance.cs");
                        Debug.LogException(ex);
                    }
                    s_eventHierarchyBuffer.Add(fightEvent.eventId, fightEvent);
                }
                try
                {
                    activeFightStatus.TriggerUpdateEvents();
                }
                catch (Exception ex2)
                {
                    Log.Error($"Exception occured while triggering update events of fight status #{activeFightStatus.fightId}.", 163, "C:\\BuildAgents\\AgentB\\work\\cub_client_win64_develop\\client\\DofusCube.Unity\\Assets\\Core\\Code\\Fight\\FightLogicExecutor.Instance.cs");
                    Debug.LogException(ex2);
                }
                s_eventHierarchyBuffer.Clear();
            }
예제 #17
0
 public void setFightEvent(FightEvent fightEvent)
 {
     this.fightEvent = fightEvent;
 }
예제 #18
0
 private void OnFight(FightEvent e)
 {
     AttackCommand(e.Attacker, e.Defender);
 }
예제 #19
0
 public override bool CanBeGroupedWith(FightEvent other)
 {
     return(false);
 }
예제 #20
0
        public static void Main(string[] args)
        {
            var csvReader   = new CsvReader(File.OpenText("/home/mfullen/Downloads/ufcfights.csv"));
            var fightEvents = new List <FightEvent>();

            var parser = new CsvParser(File.OpenText("/home/mfullen/Downloads/ufcfights.csv"));
            var index  = 0;

            while (true)
            {
                var row = parser.Read();
                if (row == null)
                {
                    break;
                }

                if (index > 0)
                {
                    var fe = new FightEvent()
                    {
                        pageUrl     = row[0],
                        eid         = int.Parse(row[1]),
                        mid         = int.Parse(row[2]),
                        event_name  = row[3],
                        event_org   = row[4],
                        event_date  = row[5],
                        event_place = row[6],
                        f1pageurl   = row[7],
                        f2pageurl   = row[8],
                        f1name      = row[9],
                        f2name      = row[10],
                        f1result    = row[11],
                        f2result    = row[12],
                        f1fid       = int.Parse(row[13]),
                        f2fid       = int.Parse(row[14]),
                        method      = row[15],
                        method_d    = row[16],
                        reff        = row[17]
                    };
                    fightEvents.Add(fe);
                }

                index++;
            }

            var fighters = new List <Fighter>();

            using (TextReader reader = File.OpenText("/home/mfullen/Downloads/ufcfighters.csv")) {
                var csv = new CsvReader(reader);
                csv.Configuration.RegisterClassMap <FighterDefinitionMap>();
                while (csv.Read())
                {
                    var record = csv.GetRecord <Fighter>();
                    fighters.Add(record);
                }
            }

            var trainingData = new List <FighterData>();
            var random       = new Random();

            foreach (var fightEvent in fightEvents)
            {
                var f1 = fighters.FirstOrDefault(f => f.Fid == fightEvent.f1fid.ToString());
                var f2 = fighters.FirstOrDefault(f => f.Fid == fightEvent.f2fid.ToString());

                if (f1 == null || f2 == null)
                {
                    continue;
                }
                string result = null;
                switch (fightEvent.f1result)
                {
                case "win":
                    result = "f1";
                    break;

                case "loss":
                    result = "f2";
                    break;

                default:
                    result = "tie";
                    break;
                }
                var td = new FighterData()
                {
                    EventDate         = fightEvent.event_date,
                    Fighter1BirthDate = f1.Birth_Date,
                    Fighter1Country   = f1.Country,
                    Fighter1Height    = f1.Height,
                    Fighter1Id        = f1.Fid,
                    Fighter1Name      = f1.Name,
                    Figther1Weight    = f1.Weight,

                    Fighter2BirthDate = f2.Birth_Date,
                    Fighter2Country   = f2.Country,
                    Fighter2Height    = f2.Height,
                    Fighter2Id        = f2.Fid,
                    Fighter2Name      = f2.Name,
                    Figther2Weight    = f2.Weight,
                    Ref    = fightEvent.reff,
                    Result = result
                };

                var shuffleWinner = random.NextDouble();

                if (shuffleWinner >= 0.5)
                {
                    if (result == "f1")
                    {
                        result = "f2";
                    }
                    else if (result == "f2")
                    {
                        result = "f1";
                    }
                    td = new FighterData()
                    {
                        EventDate         = fightEvent.event_date,
                        Fighter2BirthDate = f1.Birth_Date,
                        Fighter2Country   = f1.Country,
                        Fighter2Height    = f1.Height,
                        Fighter2Id        = f1.Fid,
                        Fighter2Name      = f1.Name,
                        Figther2Weight    = f1.Weight,

                        Fighter1BirthDate = f2.Birth_Date,
                        Fighter1Country   = f2.Country,
                        Fighter1Height    = f2.Height,
                        Fighter1Id        = f2.Fid,
                        Fighter1Name      = f2.Name,
                        Figther1Weight    = f2.Weight,
                        Ref    = fightEvent.reff,
                        Result = result
                    };
                }

                trainingData.Add(td);
            }

            var csvw = new CsvWriter(File.CreateText("training.csv"));

            csvw.WriteRecords(trainingData);

            Console.ReadKey();
        }