Esempio n. 1
0
    internal static SkillInfo NpcFindCanUseSkill(EntityInfo npc)
    {
        SkillStateInfo skStateInfo = npc.GetSkillStateInfo();
        int            priority    = -1;
        SkillInfo      skInfo      = null;
        long           curTime     = TimeUtility.GetLocalMilliseconds();

        if (npc.AutoSkillIds.Count <= 0)
        {
            return(null);
        }
        int randIndex = Helper.Random.Next(0, npc.AutoSkillIds.Count);

        skInfo = skStateInfo.GetSkillInfoById(npc.AutoSkillIds[randIndex]);
        SkillInfo selectSkill = null;

        if (null != skInfo && !skInfo.IsInCd(curTime))
        {
            selectSkill = skInfo;
        }
        else
        {
            for (int i = 0; i < npc.AutoSkillIds.Count; i++)
            {
                skInfo = skStateInfo.GetSkillInfoById(npc.AutoSkillIds[i]);
                if (null != skInfo && !skInfo.IsInCd(curTime) && skInfo.ConfigData.skillData.autoCast > priority)
                {
                    selectSkill = skInfo;
                    priority    = skInfo.ConfigData.skillData.autoCast;
                }
            }
        }
        return(selectSkill);
    }
Esempio n. 2
0
    void HandleEvent()
    {
        if (Event.current.type == EventType.MouseUp)
        {
            curSelectState = GetSelectState(Event.current.mousePosition.y);
        }

        if (Event.current.type == EventType.ContextClick)
        {
            Event evt         = Event.current;
            Rect  contextRect = new Rect(0, (curSelectState + 1) * 50, 1500, 50);

            Vector2 mousePos = evt.mousePosition;
            if (contextRect.Contains(mousePos))
            {
                // Now create the menu, add items and show it
                GenericMenu menu = new GenericMenu();

                menu.AddItem(new GUIContent("删除"), false, GenericMenuCallBack, "");

                menu.ShowAsContext();

                evt.Use();
            }
        }

        if (Event.current.type == EventType.mouseDrag)
        {
            if (curSelectState == -1 || curSelectState >= stateinfos.Count)
            {
                return;
            }
            Vector2        pos      = Event.current.mousePosition;
            SkillStateInfo info     = stateinfos[curSelectState];
            float          pos2time = (pos.x - 60) / 400;
            float          left     = info.starttime;
            float          right    = info.starttime + info.duration;
            //float delta =


            if (Mathf.Abs(pos2time - left) < 0.05f && pos2time < (left + info.duration / 2))
            {
                info.starttime = pos2time;
                info.duration  = right - pos2time;
            }
            else if (Mathf.Abs(right - pos2time) < 0.05f && pos2time > (left + info.duration / 2))
            {
                info.duration = pos2time - left;
            }
        }
    }
Esempio n. 3
0
    // 第二个窗口
    void DrawWindow1(int wndId)
    {
        {
            GUILayout.BeginHorizontal("Box", GUILayout.Width(300));
            GUILayout.FlexibleSpace();
            newstateindex = EditorGUILayout.Popup("状态", newstateindex, statenames);
            newstatename  = statenames[newstateindex];
            GUILayout.FlexibleSpace();
            newstarttime = EditorGUILayout.FloatField("开始时间:", newstarttime);
            GUILayout.FlexibleSpace();
            newduration = EditorGUILayout.FloatField("持续时间:", newduration);
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("添加"))
            {
                SkillStateInfo stateInfo = new SkillStateInfo();
                stateInfo.starttime = newstarttime;
                stateInfo.duration  = newduration;
                stateInfo.name      = newstatename;
                stateInfo.bAdded    = true;
                stateinfos.Add(stateInfo);
            }

            {
                //if (CSkillManager.Instance != null)
                //{
                //    SkillEffectData effect = CSkillManager.Instance.GetSkillEffectData(nSkillID);
                //    if (effect != null)
                //    {
                //        bool bCameraEffect=GUILayout.Toggle(effect.bCameraEffect!=0,"镜头效果");
                //        effect.bCameraEffect=bCameraEffect?1:0;
                //        bool bShakeScreen=GUILayout.Toggle(effect.bShakeScreen!=0,"震屏效果");
                //        effect.bShakeScreen=bShakeScreen?1:0;
                //    }
                //}
            }


            GUILayout.EndHorizontal();
        }

        windowOffset = GUI.BeginScrollView(new Rect(0, 60, 1000, 500), windowOffset, new Rect(0, 60, 1500, 1500));
        HandleEvent();
        DrawSkillStateGraph();

        GUI.EndScrollView();
    }
Esempio n. 4
0
 //技能相关
 /// <summary>
 /// 使用技能,由行为树调用
 /// </summary>
 /// <param name="index"></param>
 /// <param name="info"></param>
 public void UseSkill(int index, SkillStateInfo info)
 {
     if (index < skills.Count)
     {
         if (skills[index] != null)
         {
             StartCoroutine(SpellSkill(index, info));
         }
         else
         {
             Debug.Log("技能为空"); info.isDone = true;
         }
     }
     else
     {
         Debug.Log("技能下标越界"); info.isDone = true;
     }
 }
Esempio n. 5
0
    void DrawSkillStateGraph()
    {
        RefreshStates(nSkillID);

        DrawCols(6, 151);
        for (int i = 0; i < 12; i++)
        {
            DrawRow(new Vector2(60, 100 + i * 50), 30, false);
        }

        for (int i = 0; i < stateinfos.Count; i++)
        {
            SkillStateInfo sinfo = stateinfos[i];

            float x       = sinfo.starttime * 200;
            float w       = sinfo.duration * 200;
            float endtime = sinfo.starttime + sinfo.duration;

            Color color = Color.gray;

            if (curSelectState == i)
            {
                color = Color.red;
            }
            else if (sinfo.bAdded)
            {
                color = Color.yellow;
            }
            DrawRectangle(new Vector2(60 + x, 100 + i * 50 - 50), new Vector2(w, 50), color, Color.green);

            GUI.Label(new Rect(0, 100 + i * 50 - 20, 60, 20), sinfo.name);
            GUI.Label(new Rect(60 - 10 + x, 100 + i * 50 - 20, 60, 20), sinfo.starttime.ToString());
            GUI.Label(new Rect(60 - 10 + x + w, 100 + i * 50 - 20, 60, 20), endtime.ToString());
        }

        //if (sc!=null)
        //{
        //    float x=sc.fSkillTime*200;
        //    DrawRectangle(new Vector2(60+x,0), new Vector2(1,650), Color.red, Color.red);
        //}
    }
Esempio n. 6
0
    private bool CombatHandler(EntityInfo npc, AiStateInfo info, long deltaTime)
    {
        if (npc.GetSkillStateInfo().IsSkillActivated())
        {
            return(true);
        }

        EntityInfo leader = AiLogicUtility.GetLivingCharacterInfoHelper(npc, info.LeaderId);

        ScriptRuntime.Vector3 srcPos  = npc.GetMovementStateInfo().GetPosition3D();
        ScriptRuntime.Vector3 homePos = ScriptRuntime.Vector3.Zero;
        if (null != leader)
        {
            homePos = GetHomePos(npc.GetMovementStateInfo().FormationIndex, leader);
        }
        float distSqrToHome = Geometry.DistanceSquare(srcPos, homePos);

        if (distSqrToHome > npc.GohomeRange * npc.GohomeRange)
        {
            AiCommand.AiStopPursue(npc);
            info.ChangeToState((int)AiStateId.Gohome);
            return(true);
        }

        ///
        EntityInfo     attackTarget = null;
        SkillStateInfo currSkInfo   = npc.GetSkillStateInfo();
        ///找到可以使用的技能
        SkillInfo skInfo = AiLogicUtility.NpcFindCanUseSkill(npc);

        AiCommand.AiSelectSkill(npc, skInfo);
        if (skInfo == null)
        {
            //没有可以使用的技能就切换到Idle状态
            info.ChangeToState((int)PredefinedAiStateId.Idle);
            return(false);
        }

        CharacterRelation relation =
            (skInfo.TargetType == SkillTargetType.Friend ||
             skInfo.TargetType == SkillTargetType.RandFriend) ?
            CharacterRelation.RELATION_FRIEND :
            CharacterRelation.RELATION_ENEMY;

        attackTarget = AiLogicUtility.GetNearstTargetHelper(
            npc, skInfo.Distance, relation);

        if (attackTarget != null && null != skInfo)   //攻击范围内找到可攻击目标
        {
            info.Target = attackTarget.GetId();
            AiCommand.AiStopPursue(npc);
            AiCommand.AiSkill(npc, skInfo.SkillId); //攻击目标
            return(true);
        }
        attackTarget = AiLogicUtility.GetNearstTargetHelper(
            npc, npc.ViewRange, relation);
        if (attackTarget != null)                                                         //视野范围内找到可攻击目标
        {
            AiCommand.AiPursue(npc, attackTarget.GetMovementStateInfo().GetPosition3D()); // 追赶目标
            return(true);
        }

        currSkInfo.SetCurSkillInfo(0);
        AiCommand.AiStopPursue(npc);
        info.ChangeToState((int)AiStateId.Gohome);
        return(true);
    }
    private bool CombatHandler(EntityInfo npc, AiStateInfo info, long deltaTime)
    {
        info.Time += deltaTime;
        if (info.Time > 100)
        {
            info.Time = 0;
        }
        else
        {
            return(true);
        }

        if (npc.GetSkillStateInfo().IsSkillActivated())
        {
            return(true);
        }

        ScriptRuntime.Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D();
        float distSqrToHome          = Geometry.DistanceSquare(srcPos, info.HomePos);

        if (distSqrToHome > npc.GohomeRange * npc.GohomeRange)
        {
            AiCommand.AiStopPursue(npc);
            info.ChangeToState((int)AiStateId.Gohome);
            return(true);
        }

        ///
        EntityInfo     attackTarget = null;
        SkillStateInfo currSkInfo   = npc.GetSkillStateInfo();
        ///找到可以使用的技能
        SkillInfo skInfo = AiLogicUtility.NpcFindCanUseSkill(npc);

        AiCommand.AiSelectSkill(npc, skInfo);
        if (skInfo == null)
        {
            AiCommand.AiStopPursue(npc);
            info.ChangeToState((int)PredefinedAiStateId.Idle);
            return(false);
        }

        CharacterRelation relation = skInfo.ConfigData.targetType == (int)SkillTargetType.Friend ?
                                     CharacterRelation.RELATION_FRIEND :
                                     CharacterRelation.RELATION_ENEMY;

        attackTarget = AiLogicUtility.GetNearstTargetHelper(
            npc, skInfo.Distance, relation);

        if (attackTarget != null && null != skInfo) //攻击范围内找到可攻击目标
        {
            info.Target = attackTarget.GetId();
            ScriptRuntime.Vector3 targetPos = attackTarget.GetMovementStateInfo().GetPosition3D();
            float dir    = Geometry.GetYRadian(srcPos, targetPos);
            float curDir = npc.GetMovementStateInfo().GetFaceDir();
            if (Mathf.Abs(dir - curDir) > 0.157f)
            {
                npc.GetMovementStateInfo().SetWantedFaceDir(dir);
            }
            else
            {
                AiCommand.AiStopPursue(npc);
                AiCommand.AiSkill(npc, skInfo.SkillId); //攻击目标
            }
            return(true);
        }
        attackTarget = AiLogicUtility.GetNearstTargetHelper(
            npc, npc.ViewRange, relation);
        if (attackTarget != null)                                                         //视野范围内找到可攻击目标
        {
            AiCommand.AiPursue(npc, attackTarget.GetMovementStateInfo().GetPosition3D()); // 追赶目标
            return(true);
        }

        currSkInfo.SetCurSkillInfo(0);
        AiCommand.AiStopPursue(npc);
        return(true);
    }
Esempio n. 8
0
    private IEnumerator SpellSkill(int index, SkillStateInfo info)
    {
        yield return(skills[index]());

        info.isDone = true;
    }
Esempio n. 9
0
 public override void OnStart()
 {
     base.OnStart();
     info = new SkillStateInfo();
     monster.UseSkill(skillIndex, info);
 }