当前位置: 首页>>代码示例>>C#>>正文


C# Ship.SetBehavior方法代码示例

本文整理汇总了C#中Ship.SetBehavior方法的典型用法代码示例。如果您正苦于以下问题:C# Ship.SetBehavior方法的具体用法?C# Ship.SetBehavior怎么用?C# Ship.SetBehavior使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Ship的用法示例。


在下文中一共展示了Ship.SetBehavior方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DetermineBehavior

    public void DetermineBehavior(Ship leader, Ship subject)
    {
        if (subject.behavior == null)
        {
            //Debug.LogWarning("Behavior for " + subject.name + " is null.");
            subject.SetBehavior(new DoNothing(subject));
        }
        ////Debug.Log("Determining Behavior for " + subject.name + " fleet leader: " + subject.isFleetLeader);

        // Check if current should stay the same.
        if (subject.GetBehavior().KeepBehaviorCheck((AiShip)leader, (AiShip)subject))
            return;

        ////Debug.Log("Passed initial check");
        subject.GetBehavior().CallSwitch();
        //subject.SetBehavior(new DoNothing(subject));

        if (leader.GetBehavior() is Search && !subject.isFleetLeader)
        {
            Debug.Log("Search Follow");
            subject.SetBehavior(new SearchFollow(subject));
            Debug.Log("Setting Behavior Name");
            subject.behaviorName = subject.GetBehavior().ToString();
            return;
        }

        bool isHealthy = false;
        bool hasTarget = false;
        bool canSearch = false;
        bool canMultiTarget = false;
        bool hasAggressors = false;

        double health = ((subject.GetAttributes().structureHealth + subject.GetAttributes().armorHealth + subject.GetAttributes().shieldHealth) * 100) / subject.maxHealth;
        if (health > 51)
            isHealthy = true;

        // This is for MultiSoloEngage possiblity. Determine the range later.
        /*
        if (subject.type is Between certain Range)
            canMultiTarget = true;
        */

        if (subject.GetTarget() != null)
            hasTarget = true;

        if (subject.Aggressors.Count > 0)
            hasAggressors = true;

        if (subject.isFleetLeader == true && !hasAggressors && isHealthy && !hasTarget)
            canSearch = true;

        // Healthy Behaviors
        if (isHealthy)
        {
            if (leader.GetBehavior() is TeamEngage && leader.target != null)
            {
                subject.SetBehavior(new TeamEngage(subject));
                subject.behaviorName = subject.GetBehavior().ToString();
                return;
            }

            if (leader.targetFleet != null)
                counterThreat = RealThreatDeterminer(subject.GetMyFleet(), leader.targetFleet);
            else
                goto SkipHealthy;

            // If target is threatening, Fight with team.
            if (hasTarget && counterThreat < 20 && subject.isFleetLeader)
            {
                ////Debug.Log("Team Engaging");
                subject.SetBehavior(new TeamEngage(subject));// Team Engage
                subject.behaviorName = subject.GetBehavior().ToString();
                return;
            }

            // Solo Engage
            if (counterThreat >= 20 )
            {
                ////Debug.Log("Solo Engaging " + subject.gameObject.name);
                int count = 0;
                int threatLevel = subject.GetAttributes().threatLevel;
                float threatHigh = threatLevel * 2;
                float threatLow = -5;

                // Attacks any players in fleet first.
                int pcount = leader.targetFleet.pFleet.Count;
                if (leader.targetFleet.pFleet.Count > 0)
                {
                    subject.SetTargetShip(leader.targetFleet.pFleet[rnd.Next(0, pcount - 1)]);
                    subject.SetBehavior(new SoloEngage(subject));
                    subject.behaviorName = subject.GetBehavior().ToString();
                    return;
                }

                count = 0;

                int acount = leader.targetFleet.fleet.Count;
                if (acount > 0)
                {
                    subject.SetTargetShip(leader.targetFleet.fleet[rnd.Next(0, acount - 1)]);
//.........这里部分代码省略.........
开发者ID:KenReaGameDev,项目名称:Apparent-Horizon,代码行数:101,代码来源:BehaviorDeterminerAiShip.cs

示例2: RequestTargetChange

    //TODO: Bug! Doesn't take into account the fleet may no longer exist or have any ships.
    //TODO: Make requests for targets limited per second per ship.
    public void RequestTargetChange(Ship subject)
    {
        if (!leader || leader.targetFleet == null || leader.targetFleet.isEmpty)
            return;

        int count = 0;
        int threatLevel = subject.GetAttributes().threatLevel;
        float threatHigh = threatLevel * 2;
        float threatLow = -5;

        if (leader.targetFleet.pFleet.Count > 0)
        {
            int pcount = leader.targetFleet.pFleet.Count;
            subject.SetTargetShip(leader.targetFleet.pFleet[rnd.Next(0, pcount)]);
            subject.SetBehavior(new SoloEngage(subject));
            subject.behaviorName = subject.GetBehavior().ToString();
            return;
        }

        try
        {
            subject.target = null;

            for (int ndx = 0; ndx < leader.targetFleet.pFleet.Count; ndx++)
            {
                if (Vector3.Distance(subject.transform.position, leader.targetFleet.pFleet[ndx].transform.position) > subject.attributes.range * 3)
                    continue;
                else
                    subject.SetTargetShip(leader.targetFleet.pFleet[ndx]);
            }

            if (subject.target != null)
                return;

            for (int ndx = 0; ndx < leader.targetFleet.fleet.Count; ndx++)
            {
                if (Vector3.Distance(subject.transform.position, leader.targetFleet.fleet[ndx].transform.position) > subject.attributes.range * 3)
                    continue;
                else
                    subject.SetTargetShip(leader.targetFleet.fleet[ndx]);
            }
            if (subject.target != null)
                return;

        }
        catch
        {
            if (!subject)
            {
                //Debug.Log("RTC Subject is Dead");
                return;
            }

            if (!leader)
            {
                //Debug.Log("RTC Leader is Dead");
                return;
            }

            if (leader.targetFleet == null)
            {
                //Debug.Log("RTC TargetFleet is Dead");
                return;
            }

            if (leader.targetFleet.fleet.Count < 1)
            {
                //Debug.Log("RTC TargetFleet Fleet is Empty");
                leader.targetFleet = null;
                return;
            }
        }

        if (subject.target == null)
        {
            //Debug.Log("No Potential Targets");
        }
    }
开发者ID:KenReaGameDev,项目名称:Apparent-Horizon,代码行数:80,代码来源:BehaviorDeterminerAiShip.cs


注:本文中的Ship.SetBehavior方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。