Exemple #1
0
        public void Act()
        {
            if (AI == null)
            {
                return;
            }

            (string actionName, NpcAction actionType) = AI.GetAction(this);

            Animation       = AnimationStorage.GetSequenceIdBySequenceName(Model, actionName);
            CurrentAction   = actionType;
            CurrentMovement = AI.GetMovementAction(this);

            switch (CurrentAction)
            {
            case NpcAction.Idle:
                Move(MobMovement.Hold);     // temp, maybe remove the option to specify movement in AI
                break;

            case NpcAction.Bore:
                Move(MobMovement.Hold);     // temp, maybe remove the option to specify movement in AI
                break;

            case NpcAction.Walk:
                Move(CurrentMovement);
                break;

            case NpcAction.Jump:
            default:
                break;
            }
        }
Exemple #2
0
    public NpcAction GetNpcAction(int npcId)
    {
        NpcAction npcAction = null;

        m_npcActionDict.TryGetValue(npcId, out npcAction);
        return(npcAction);
    }
Exemple #3
0
 private void ChooseIdle()
 {
     if (NpcActionExtensions.IsSpecialIdle(this.CurrentAction))
     {
         this.CurrentAction = NpcAction.Idle;
     }
     else
     {
         float num1 = RandomHelper.Unit();
         float num2 = (float)(1 + FezMath.AsNumeric(this.CanIdle2) + FezMath.AsNumeric(this.CanIdle3));
         if ((double)num1 < 1.0 / (double)num2)
         {
             this.CurrentAction = NpcAction.Idle;
         }
         else if ((double)num2 > 1.0 && (double)num1 < 2.0 / (double)num2)
         {
             this.CurrentAction = this.CanIdle2 ? NpcAction.Idle2 : NpcAction.Idle3;
         }
         else
         {
             if ((double)num2 <= 2.0 || (double)num1 >= 3.0 / (double)num2)
             {
                 return;
             }
             this.CurrentAction = NpcAction.Idle3;
         }
     }
 }
Exemple #4
0
    //同步Npc信息
    public void SyncNpcInfo(PlayerActor stationPlayerActor)
    {
        float posX, posY, posZ, angleX, angleY, angleZ = 0.0f;
        int   npcId;
        int   npcType;
        List <PlayerActor> stationPlayerActorList = new List <PlayerActor>();

        var enumerator = m_npcActionDict.GetEnumerator();

        while (enumerator.MoveNext())
        {
            NpcAction npcAction    = enumerator.Current.Value;
            Transform npcTransform = npcAction.transform;
            posX    = npcTransform.localPosition.x;
            posY    = npcTransform.localPosition.y;
            posZ    = npcTransform.localPosition.z;
            angleX  = npcTransform.localEulerAngles.x;
            angleY  = npcTransform.localEulerAngles.y;
            angleZ  = npcTransform.localEulerAngles.z;
            npcId   = npcAction.NpcId;
            npcType = (int)npcAction.NpcType;
            GameGlobalComponent.NpcSync.SendNpcPositionRelink(stationPlayerActor, posX, posY, posZ, angleX, angleY, angleZ, npcId, npcType,
                                                              npcAction.StationIndex, (System.UInt16)npcAction.NpcActionStatus);
        }
        enumerator.Dispose();
    }
 public void NpcInteractStateSaved()
 {
     try
     {
         var        mrLegit      = this.MrLegitlyFestive;
         NpcOptions user1Options = mrLegit.GetOptions(Context.User1).Result;
         foreach (var option in user1Options.Options)
         {
             NpcStateRepo.ClearNpcState(CritterServer.Contract.Npc.MrLegitlyFestive, Context.User1.Id);
             NpcAction action = mrLegit.Interact(option.Value, Context.User1).Result;
             Assert.NotEqual("Uh oh!", action.Title);
             NpcAction action2 = mrLegit.Interact(option.Value, Context.User1).Result;
             Assert.Equal("Uh oh!", action2.Title);
         }
     }
     catch (AggregateException a)
     {
         Console.WriteLine(a.Message);
         foreach (Exception innerException in a.Flatten().InnerExceptions)
         {
             Console.WriteLine(innerException.Message);
         }
         throw;
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         throw;
     }
 }
    private List <NpcAction> ReadNpcActionList(XmlNode _npcNode)
    {
        List <NpcAction> npcActionList = new List <NpcAction>();

        foreach (XmlNode XmlAction in _npcNode.ChildNodes)
        {
            NpcAction npcAction = new NpcAction();
            npcAction.npcName    = ((XmlElement)XmlAction).GetAttribute("name");
            npcAction.actionType = ((XmlElement)XmlAction).GetAttribute("actionType");
            if (npcAction.actionType == "FollowToAim")
            {
                npcAction.aimGameObject = ((XmlElement)XmlAction).GetAttribute("aimGameObject");
            }
            else if (npcAction.actionType == "Attack")
            {
                npcAction.aimGameObject = ((XmlElement)XmlAction).GetAttribute("aimGameObject");
            }
            else if (npcAction.actionType == "RunToAim")
            {
                npcAction.aimGameObject = ((XmlElement)XmlAction).GetAttribute("aimGameObject");
            }
            else if (npcAction.actionType == "Instance")
            {
                npcAction.aimGameObject = ((XmlElement)XmlAction).GetAttribute("aimGameObject");
                npcAction.objPosition.x = float.Parse(((XmlElement)XmlAction).GetAttribute("positionX"));
                npcAction.objPosition.y = float.Parse(((XmlElement)XmlAction).GetAttribute("positionY"));
                npcAction.objPosition.z = float.Parse(((XmlElement)XmlAction).GetAttribute("positionZ"));
            }
            npcActionList.Add(npcAction);
        }
        return(npcActionList);
    }
    private void ToggleAction()
    {
        NpcAction prevAction = CurrentAction;

        RandomizeAction();
        TimeUntilActionChange = UnityEngine.Random.Range(2f, 5f);
        TimeSinceActionChange = 0f;
    }
Exemple #8
0
 public void RemoveNpcAction(UInt16 stationIndex, NpcAction npcAction)
 {
     if (System.Object.ReferenceEquals(npcAction, null))
     {
         return;
     }
     m_stationEngine.RemoveNpcAction(stationIndex, npcAction);
 }
Exemple #9
0
        private void OnInteracted(NpcActionTypeEnum actionType, NpcAction action, Character character)
        {
            Action <Npc, NpcActionTypeEnum, NpcAction, Character> interacted = this.Interacted;

            if (interacted != null)
            {
                interacted(this, actionType, action, character);
            }
        }
Exemple #10
0
 public void InteractWith(NpcActionTypeEnum actionType, Character dialoguer)
 {
     if (this.CanInteractWith(actionType, dialoguer))
     {
         NpcAction npcAction = this.Actions.First((NpcAction entry) => entry.ActionType == actionType && entry.CanExecute(this, dialoguer));
         npcAction.Execute(this, dialoguer);
         this.OnInteracted(actionType, npcAction, dialoguer);
     }
 }
Exemple #11
0
    public NpcAction Clone()
    {
        NpcAction tempObj = (NpcAction)this.MemberwiseClone();

        if (AnimID != null)
        {
            tempObj.AnimID = new List <int>(this.AnimID);//(int[])this._CameraGroup.Clone();
        }
        return(tempObj);
    }
Exemple #12
0
        private void OnInteracted(NpcActionTypeEnum actionType, NpcAction action, Character character)
        {
            character.OnInteractingWith(this, actionType, action);
            var handler = Interacted;

            if (handler != null)
            {
                handler(this, actionType, action, character);
            }
        }
    public void AddNpcAction(UInt16 stationIndex, NpcAction npcAction)
    {
        Station station = GetStation(stationIndex);

        if (System.Object.ReferenceEquals(station, null))
        {
            return;
        }
        station.AddNpcAction(npcAction);
    }
    public void RemoveNpcAction(UInt16 stationIndex, NpcAction npcAction)
    {
        Station station = GetStation(stationIndex);

        if (System.Object.ReferenceEquals(station, null))
        {
            return;
        }
        station.RemoveNpcAction(npcAction.NpcActionStatus, npcAction.NpcId);
    }
        public static bool IsSpecialIdle(this NpcAction action)
        {
            switch (action)
            {
            case NpcAction.Idle2:
            case NpcAction.Idle3:
                return(true);

            default:
                return(false);
            }
        }
Exemple #16
0
 public void AddNpcAction(NpcAction npcAction)
 {
     if (npcAction == null)
     {
         return;
     }
     npcAction.NpcId = System.Threading.Interlocked.Increment(ref StationEngine.StartNpcId);
     if (m_npcActionDict.ContainsKey(npcAction.NpcId) == false)
     {
         m_npcActionDict.Add(npcAction.NpcId, npcAction);
     }
 }
        public static bool AllowsRandomChange(this NpcAction action)
        {
            switch (action)
            {
            case NpcAction.Idle:
            case NpcAction.Idle3:
            case NpcAction.Walk:
                return(true);

            default:
                return(false);
            }
        }
    public void AddNpcAction(NpcAction npcAction)
    {
        if (System.Object.ReferenceEquals(npcAction, null))
        {
            return;
        }
        NpcMgr npcMgr = GetNpcMgr(npcAction.NpcActionStatus);

        if (System.Object.ReferenceEquals(npcMgr, null))
        {
            return;
        }
        npcMgr.AddNpcAction(npcAction);
    }
Exemple #19
0
    public void SyncNpcInfo()
    {
        //功能实现方式,是给Npc设置同步开关,打开开关,Npc主动向客户端发送Npc的消息,关闭开关,则只有Npc产生位移或动画时才发送Npc消息
        var enumerator = m_npcActionDict.GetEnumerator();

        while (enumerator.MoveNext())
        {
            NpcAction npcAction = enumerator.Current.Value;
            if (npcAction != null)
            {
                npcAction.ClientReconnectFlag = true;
            }
        }
        enumerator.Dispose();
    }
        public static bool Loops(this NpcAction action)
        {
            switch (action)
            {
            case NpcAction.Idle2:
            case NpcAction.Turn:
            case NpcAction.Burrow:
            case NpcAction.Hide:
            case NpcAction.ComeOut:
            case NpcAction.TakeOff:
            case NpcAction.Land:
                return(false);

            default:
                return(true);
            }
        }
    private static void NNN(NpcMgr npcMgr, Transform npcActionStatusTrans, System.UInt16 stationIndex)
    {
        int npcCount = npcActionStatusTrans.childCount;

        for (int i = 0; i < npcCount; ++i)
        {
            Transform npcTrans  = npcActionStatusTrans.GetChild(i);
            NpcAction npcAction = npcTrans.GetComponent <NpcAction> ();
            if (npcAction == null)
            {
                continue;
            }
            // int npcId = Interlocked.Increment(ref StationEngine.StartNpcId); //原子操作
            // npcAction.NpcId = npcId;
            npcAction.StationIndex = stationIndex;
            npcMgr.AddNpcAction(npcAction);
        }
    }
Exemple #22
0
        private void ToggleAction()
        {
            NpcAction npcAction = this.CurrentAction;

            if (this.initialized)
            {
                this.RandomizeAction();
            }
            else
            {
                this.CurrentAction = this.CanIdle ? NpcAction.Idle : NpcAction.Walk;
            }
            this.TimeUntilActionChange = new TimeSpan(0, 0, RandomHelper.Random.Next(2, 5));
            this.TimeSinceActionChange = TimeSpan.Zero;
            if (this.initialized && this.CurrentAction == npcAction)
            {
                return;
            }
            this.UpdateAction();
        }
        private static void ParseAI(XmlDocument document)
        {
            XmlNode behaviorsNode = document.SelectSingleNode("/ai/behavior");

            MobAI ai = new MobAI();

            foreach (XmlNode node in behaviorsNode)
            {
                NpcState          stateValue     = GetMobState(node.Name);
                NpcAction         newActionValue = GetMobAction(node.Attributes["action"]?.Value);
                MobMovement       movementValue  = GetMobMovement(node.Attributes["movement"]?.Value);
                MobAI.Condition[] conditions     = GetConditions(/*node*/);

                ai.Rules.TryAdd(stateValue, (newActionValue, movementValue, Array.Empty <MobAI.Condition>()));
            }

            string aiName = document.BaseURI.Split("MobAI/")[1];

            AiTable.Add(aiName, ai);
        }
Exemple #24
0
 public IEnumerator performAction(NpcAction action)
 {
     if (action.actionType == "Attack")
     {
         GameObject.Find(action.npcName).tag = "AttackNpc";
         yield return(StartCoroutine(GameObject.Find(action.npcName).GetComponent <NpcControl>().Attack(4.0f, 3.0f, GameObject.Find(action.aimGameObject))));
     }
     else if (action.actionType == "Talk")
     {
         GameObject.Find(action.npcName).tag = "StoryNpc";
         yield return(StartCoroutine(GameObject.Find(action.npcName).GetComponent <NpcControl>().Talk()));
     }
     else if (action.actionType == "RunToAim")
     {
         GameObject.Find(action.npcName).tag = "StoryNpc";
         GameObject obj = GameObject.Find(action.aimGameObject);
         yield return(StartCoroutine(GameObject.Find(action.npcName).GetComponent <NpcControl>().RunToAim(obj)));
     }
     else if (action.actionType == "FollowToAim")
     {
         GameObject.Find(action.npcName).tag = "StoryNpc";
         yield return(StartCoroutine(GameObject.Find(action.npcName).GetComponent <NpcControl>().FollowAim(GameObject.Find(action.aimGameObject))));
     }
     else if (action.actionType == "Instance")
     {
         GameObject npx      = Resources.Load("Prefabs/NpcPrefab/" + action.aimGameObject) as GameObject;
         GameObject heiYiRen = GameObject.Instantiate(npx, action.objPosition, Quaternion.AngleAxis(180.0f, Vector3.up)) as GameObject;
         heiYiRen.tag = "StoryNpc";
         //yield return null;
     }
     else if (action.actionType == "Destroy")
     {
         GameObject.Destroy(GameObject.Find(action.npcName), 1.0f);
     }
     else
     {
         GameObject.Find(action.npcName).tag = "StoryNpc";
     }
     yield return(0);
 }
Exemple #25
0
    public void Fill(NpcInstance npc)
    {
        Animations.Clear();
        CurrentAction = NpcAction.None;

        NPC = npc;

        MeshFilter meshFilter = gameObject.AddComponent <MeshFilter>();

        meshFilter.sharedMesh = FezManager.Instance.BackgroundPlaneMesh;

        meshRenderer = gameObject.AddComponent <MeshRenderer>();

        foreach (NpcAction action in Enum.GetValues(typeof(NpcAction)))
        {
            if (action == NpcAction.None ||
                action == NpcAction.Walk ||
                action == NpcAction.Idle ||
                action == NpcAction.Talk)
            {
                continue;
            }
            if (!NPC.Actions.ContainsKey(action) && FezManager.Instance.AssetExists("character animations/" + NPC.Name + "/" + action))
            {
                NPC.Actions.Add(action, new NpcActionContent()
                {
                    AnimationName = action.ToString()
                });
            }
        }

        foreach (KeyValuePair <NpcAction, NpcActionContent> pair in NPC.Actions)
        {
            NpcAction        action        = pair.Key;
            NpcActionContent actionContent = pair.Value;

            AnimatedTexture texAnim = FezManager.Instance.GetTextureOrOther("character animations/" + NPC.Name + "/" + actionContent.AnimationName) as AnimatedTexture;
            texAnim.Timing.Loop = true;
            texAnim.Timing.Loop =
                action != NpcAction.Idle2 &&
                action != NpcAction.Turn &&
                action != NpcAction.Burrow &&
                action != NpcAction.Hide &&
                action != NpcAction.ComeOut &&
                action != NpcAction.TakeOff &&
                action != NpcAction.Land;
            actionContent.Animation = texAnim;

            Texture2D tex2D = texAnim.Texture;
            meshRenderer.material = Instantiate(tex2D.GenMaterial(FezManager.Instance.BackgroundPlaneMaterial));
            meshRenderer.sharedMaterial.mainTexture.wrapMode = TextureWrapMode.Clamp;

            FezUnityAnimatedTexture animation = gameObject.AddComponent <FezUnityAnimatedTexture>();
            animation.Fill(texAnim);
            animation.enabled = false;

            Animations[action] = animation;
        }

        using (BinaryReader metadataReader = FezManager.Instance.ReadFromPack("character animations/" + NPC.Name + "/metadata")) {
            if (metadataReader != null)
            {
                npc.FillMetadata(FmbUtil.ReadObject(metadataReader) as NpcMetadata);
            }
        }

        CanIdle  = Animations.ContainsKey(NpcAction.Idle);
        CanIdle2 = Animations.ContainsKey(NpcAction.Idle2);
        CanIdle3 = Animations.ContainsKey(NpcAction.Idle3);
        CanWalk  = Animations.ContainsKey(NpcAction.Walk);
        CanTalk  = Animations.ContainsKey(NpcAction.Talk);
        CanTurn  = Animations.ContainsKey(NpcAction.Turn);

        CurrentAction = CanIdle ? NpcAction.Idle : NpcAction.Walk;

        if (!CanTalk)
        {
            return;
        }

        SpeechBubble = new GameObject("Speech Bubble");
        SpeechBubble.transform.parent        = transform;
        SpeechBubble.transform.localPosition = Vector3.up * transform.localScale.y * 0.5f + Vector3.forward * transform.localScale.z * 0.3f;
        SpeechBubble.transform.localScale    = new Vector3(
            0.01f / transform.localScale.x,
            0.01f / transform.localScale.y,
            1f
            );

        Canvas        bubbleCanvas    = SpeechBubble.AddComponent <Canvas>();
        RectTransform bubbleTransform = SpeechBubble.GetComponent <RectTransform>();

        bubbleTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 200f);
        bubbleTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 100f);

        SpeechBubbleCanvasGroup = SpeechBubble.AddComponent <CanvasGroup>();

        AddSpeechCorner(0f, 0f, "speechbubblese");
        AddSpeechCorner(0f, 1f, "speechbubblese");
        AddSpeechCorner(1f, 0f, "speechbubblese");
        AddSpeechCorner(1f, 1f, "speechbubblese");
        AddSpeechFill(0, "fullblack");
        AddSpeechFill(1, "fullblack");

        GameObject textObj = new GameObject("Text");

        textObj.transform.parent        = SpeechBubble.transform;
        textObj.transform.localPosition = Vector3.zero;
        textObj.transform.localScale    = new Vector3(0.25f, 0.25f, 1f);

        Text text = textObj.AddComponent <Text>();

        text.font = FezManager.Instance.SpeechFont;
        // text.fontSize = 50;
        text.fontSize         = 75;
        text.alignment        = TextAnchor.MiddleCenter;
        text.verticalOverflow = VerticalWrapMode.Overflow;
        text.text             = "";

        RectTransform textTransform = textObj.GetComponent <RectTransform>();

        // textTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 200f);
        // textTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 243f);
        textTransform.anchorMin = new Vector2(0f, 0f);
        textTransform.anchorMax = new Vector2(1f, 1f);

        CurrentTextOpacity = 0f;
    }
        public override async Task <NpcAction> Interact(int action, User activeUser)
        {
            var response = new NpcAction();

            if (action == (int)Actions.TakeAGift)
            {
                using (var trans = transactionFactory.Create())
                {
                    var states = await domain.GetNpcStates(Id, activeUser.Id);

                    if (states?.Count() > 0)
                    {
                        response.Message = "Come back tomorrow, don't be greedy!";
                        response.Title   = "Uh oh!";
                        //response.ImagePath = "" seems like it should be configurable, but this is code...
                    }
                    else
                    {
                        //get config
                        var cfgs = await GetItemConfigs(configRepo);

                        if (cfgs.Count() > 1)
                        {
                            Log.Logger.Warning($"NPC {Id} has {cfgs.Count()} valid item generation cfgs right now, thats a weird state!");
                        }
                        //create item
                        var items = new List <InventoryItemDetails>();
                        foreach (var cfg in cfgs.Where(c => !c.StoreId.HasValue))
                        {
                            items.AddRange(await domain.SelectItemsFromConfig(cfg, activeUser));
                        }
                        //give it
                        foreach (var item in items)
                        {
                            if (item.Item.OwnerUserId == null) //give
                            {
                                if (await domain.ChangeItemOwner(item.Item.Id, activeUser.Id, null))
                                {
                                    response.AddedItems.Add(item);
                                }
                            }
                            if (item.Item.OwnerUserId == activeUser.Id) //take //TODO remove this, just using MrLF as a proof of concept. MrLF is a giver.
                            {
                                if (await domain.ChangeItemOwner(item.Item.Id, null, activeUser.Id))
                                {
                                    response.RemovedItems.Add(item);
                                }
                            }
                            else //do nothing - log and skip
                            {
                                Log.Logger.Error($"NPC {Id} has selected an invalid item to reappropriate - item {item.Item.Id} is owned by" +
                                                 $" {item.Item.OwnerUserId} and not fit for an action with {activeUser.Id}");
                            }
                        }

                        response.Message = $"Merry Happy! Mr. Legitly Festive gives you {response.AddedItems.Count()} items!";

                        //save state
                        var state = new NpcState();
                        state.NpcId      = Id;
                        state.UserId     = activeUser.Id;
                        state.Expiration = DateTime.UtcNow.Date.AddDays(1);
                        await domain.SaveNpcState(state);
                    }
                    //respond
                    trans.Complete();
                    return(response);
                }
            }

            throw new CritterException("Invalid action for Mr Legitly Festive! Try a different action.", $"User {activeUser.Id} tried to {action} Mr. LegitlyFestive.", System.Net.HttpStatusCode.BadRequest);
        }
Exemple #27
0
 private void ToggleAction()
 {
   NpcAction npcAction = this.CurrentAction;
   if (this.initialized)
     this.RandomizeAction();
   else
     this.CurrentAction = this.CanIdle ? NpcAction.Idle : NpcAction.Walk;
   this.TimeUntilActionChange = new TimeSpan(0, 0, RandomHelper.Random.Next(2, 5));
   this.TimeSinceActionChange = TimeSpan.Zero;
   if (this.initialized && this.CurrentAction == npcAction)
     return;
   this.UpdateAction();
 }
Exemple #28
0
 public void AddNpcAction(UInt16 stationIndex, NpcAction npcAction)
 {
     m_stationEngine.AddNpcAction(stationIndex, npcAction);
 }
Exemple #29
0
        private void RandomizeAction()
        {
            switch (this.CurrentAction)
            {
            case NpcAction.Turn:
                this.Turn();
                break;

            case NpcAction.Burrow:
                ServiceHelper.RemoveComponent <NpcState>(this);
                break;

            case NpcAction.TakeOff:
                this.CurrentAction = NpcAction.Fly;
                this.UpdateAction();
                break;

            case NpcAction.Land:
                this.CurrentAction = NpcAction.Idle;
                this.UpdateAction();
                break;

            default:
                if ((RandomHelper.Probability(0.5) || !this.CanWalk) && this.CanIdle)
                {
                    if (this.CanWalk || RandomHelper.Probability(0.5))
                    {
                        this.ChooseIdle();
                        break;
                    }
                    else if (this.CanTurn)
                    {
                        this.CurrentAction = NpcAction.Turn;
                        break;
                    }
                    else
                    {
                        this.Turn();
                        break;
                    }
                }
                else
                {
                    if (!this.CanWalk)
                    {
                        throw new InvalidOperationException("This NPC can't walk or idle!");
                    }
                    if ((double)this.WalkStep == 1.0 || (double)this.WalkStep == 0.0)
                    {
                        if (this.CanIdle && RandomHelper.Probability(0.5))
                        {
                            this.ChooseIdle();
                            break;
                        }
                        else if (this.CanTurn)
                        {
                            this.CurrentAction = NpcAction.Turn;
                            break;
                        }
                        else
                        {
                            this.Turn();
                            break;
                        }
                    }
                    else if (this.CanTurn && RandomHelper.Probability(0.5))
                    {
                        this.CurrentAction = NpcAction.Turn;
                        break;
                    }
                    else
                    {
                        this.CurrentAction = NpcAction.Walk;
                        break;
                    }
                }
            }
        }
Exemple #30
0
 private void RandomizeAction()
 {
   switch (this.CurrentAction)
   {
     case NpcAction.Turn:
       this.Turn();
       break;
     case NpcAction.Burrow:
       ServiceHelper.RemoveComponent<NpcState>(this);
       break;
     case NpcAction.TakeOff:
       this.CurrentAction = NpcAction.Fly;
       this.UpdateAction();
       break;
     case NpcAction.Land:
       this.CurrentAction = NpcAction.Idle;
       this.UpdateAction();
       break;
     default:
       if ((RandomHelper.Probability(0.5) || !this.CanWalk) && this.CanIdle)
       {
         if (this.CanWalk || RandomHelper.Probability(0.5))
         {
           this.ChooseIdle();
           break;
         }
         else if (this.CanTurn)
         {
           this.CurrentAction = NpcAction.Turn;
           break;
         }
         else
         {
           this.Turn();
           break;
         }
       }
       else
       {
         if (!this.CanWalk)
           throw new InvalidOperationException("This NPC can't walk or idle!");
         if ((double) this.WalkStep == 1.0 || (double) this.WalkStep == 0.0)
         {
           if (this.CanIdle && RandomHelper.Probability(0.5))
           {
             this.ChooseIdle();
             break;
           }
           else if (this.CanTurn)
           {
             this.CurrentAction = NpcAction.Turn;
             break;
           }
           else
           {
             this.Turn();
             break;
           }
         }
         else if (this.CanTurn && RandomHelper.Probability(0.5))
         {
           this.CurrentAction = NpcAction.Turn;
           break;
         }
         else
         {
           this.CurrentAction = NpcAction.Walk;
           break;
         }
       }
   }
 }
Exemple #31
0
 private void Turn()
 {
     this.LookingDirection = FezMath.GetOpposite(this.LookingDirection);
     this.UpdateRotation();
     this.CurrentAction = this.CanWalk ? NpcAction.Walk : NpcAction.Idle;
 }
Exemple #32
0
 private void Fly(TimeSpan elapsed)
 {
   if (!this.flyRight.HasValue)
     this.flyRight = new Vector3?(Vector3.Transform(Vector3.Right, this.Group.Rotation));
   if ((!this.FlyingBack || this.Npc.ActorType != ActorType.Owl) && FezMath.AlmostEqual(FezMath.Dot(FezMath.Abs(Vector3.Transform(Vector3.Right, this.Group.Rotation)), FezMath.Abs(this.flyRight.Value)), 0.0f, 0.1f))
   {
     NpcState npcState = this;
     Vector3? nullable1 = npcState.flyRight;
     Vector3 vector3 = Vector3.Transform(Vector3.Right, this.Group.Rotation);
     Vector3? nullable2 = nullable1.HasValue ? new Vector3?(nullable1.GetValueOrDefault() + vector3) : new Vector3?();
     npcState.flyRight = nullable2;
   }
   this.flySpeed = Vector2.Lerp(this.flySpeed, new Vector2(4f, 3f), 0.03333334f);
   Vector2 vector2 = this.flySpeed * ((1f - FezMath.Frac(this.CurrentTiming.Step + 0.75f)) * new Vector2(0.4f, 0.6f) + new Vector2(0.6f, 0.4f));
   this.Position += (float) elapsed.TotalSeconds * (vector2.X * this.flyRight.Value + Vector3.Up * vector2.Y * (this.FlyingBack ? -1f : 1f));
   if (FezMath.IsOrthographic(this.CameraManager.Viewpoint) && this.CameraManager.ViewTransitionReached)
   {
     Vector3 b = FezMath.ForwardVector(this.CameraManager.Viewpoint);
     if (this.InBackground)
       b *= -1f;
     NearestTriles nearestTriles = this.LevelManager.NearestTrile(this.Position, QueryOptions.Simple);
     TrileInstance trileInstance = nearestTriles.Surface ?? nearestTriles.Deep;
     if (trileInstance != null)
     {
       Vector3 a = trileInstance.Center + trileInstance.TransformedSize / 2f * -b;
       Vector3 vector3 = FezMath.DepthMask(this.CameraManager.Viewpoint);
       if ((double) FezMath.Dot(this.Position, b) > (double) FezMath.Dot(a, b))
         this.Position = this.Position * FezMath.ScreenSpaceMask(this.CameraManager.Viewpoint) + a * vector3 - b;
     }
   }
   if (this.CurrentTiming.Frame == 0 && this.lastFrame != 0)
     SoundEffectExtensions.EmitAt(this.flySound, this.Position);
   this.lastFrame = this.CurrentTiming.Frame;
   if (this.FlyingBack)
   {
     if ((double) this.Position.Y > (double) this.Npc.Position.Y)
       return;
     this.Position = this.Npc.Position;
     this.CurrentAction = NpcAction.Land;
     this.flySpeed = Vector2.Zero;
     this.UpdateAction();
     this.FlyingBack = false;
     this.flyRight = new Vector3?();
   }
   else
   {
     if (this.CameraManager.Frustum.Contains(new BoundingBox(this.Position - Vector3.One, this.Position + Vector3.One)) != ContainmentType.Disjoint)
       return;
     if (this.MayComeBack)
     {
       this.OwlInvisible = true;
       this.MayComeBack = false;
       this.CurrentAction = NpcAction.Idle;
       this.flySpeed = Vector2.Zero;
       this.flyRight = new Vector3?();
       this.UpdateAction();
     }
     else
       ServiceHelper.RemoveComponent<NpcState>(this);
   }
 }
Exemple #33
0
 private void ChooseIdle()
 {
   if (NpcActionExtensions.IsSpecialIdle(this.CurrentAction))
   {
     this.CurrentAction = NpcAction.Idle;
   }
   else
   {
     float num1 = RandomHelper.Unit();
     float num2 = (float) (1 + FezMath.AsNumeric(this.CanIdle2) + FezMath.AsNumeric(this.CanIdle3));
     if ((double) num1 < 1.0 / (double) num2)
       this.CurrentAction = NpcAction.Idle;
     else if ((double) num2 > 1.0 && (double) num1 < 2.0 / (double) num2)
     {
       this.CurrentAction = this.CanIdle2 ? NpcAction.Idle2 : NpcAction.Idle3;
     }
     else
     {
       if ((double) num2 <= 2.0 || (double) num1 >= 3.0 / (double) num2)
         return;
       this.CurrentAction = NpcAction.Idle3;
     }
   }
 }
Exemple #34
0
        private void Fly(TimeSpan elapsed)
        {
            if (!this.flyRight.HasValue)
            {
                this.flyRight = new Vector3?(Vector3.Transform(Vector3.Right, this.Group.Rotation));
            }
            if ((!this.FlyingBack || this.Npc.ActorType != ActorType.Owl) && FezMath.AlmostEqual(FezMath.Dot(FezMath.Abs(Vector3.Transform(Vector3.Right, this.Group.Rotation)), FezMath.Abs(this.flyRight.Value)), 0.0f, 0.1f))
            {
                NpcState npcState  = this;
                Vector3? nullable1 = npcState.flyRight;
                Vector3  vector3   = Vector3.Transform(Vector3.Right, this.Group.Rotation);
                Vector3? nullable2 = nullable1.HasValue ? new Vector3?(nullable1.GetValueOrDefault() + vector3) : new Vector3?();
                npcState.flyRight = nullable2;
            }
            this.flySpeed = Vector2.Lerp(this.flySpeed, new Vector2(4f, 3f), 0.03333334f);
            Vector2 vector2 = this.flySpeed * ((1f - FezMath.Frac(this.CurrentTiming.Step + 0.75f)) * new Vector2(0.4f, 0.6f) + new Vector2(0.6f, 0.4f));

            this.Position += (float)elapsed.TotalSeconds * (vector2.X * this.flyRight.Value + Vector3.Up * vector2.Y * (this.FlyingBack ? -1f : 1f));
            if (FezMath.IsOrthographic(this.CameraManager.Viewpoint) && this.CameraManager.ViewTransitionReached)
            {
                Vector3 b = FezMath.ForwardVector(this.CameraManager.Viewpoint);
                if (this.InBackground)
                {
                    b *= -1f;
                }
                NearestTriles nearestTriles = this.LevelManager.NearestTrile(this.Position, QueryOptions.Simple);
                TrileInstance trileInstance = nearestTriles.Surface ?? nearestTriles.Deep;
                if (trileInstance != null)
                {
                    Vector3 a       = trileInstance.Center + trileInstance.TransformedSize / 2f * -b;
                    Vector3 vector3 = FezMath.DepthMask(this.CameraManager.Viewpoint);
                    if ((double)FezMath.Dot(this.Position, b) > (double)FezMath.Dot(a, b))
                    {
                        this.Position = this.Position * FezMath.ScreenSpaceMask(this.CameraManager.Viewpoint) + a * vector3 - b;
                    }
                }
            }
            if (this.CurrentTiming.Frame == 0 && this.lastFrame != 0)
            {
                SoundEffectExtensions.EmitAt(this.flySound, this.Position);
            }
            this.lastFrame = this.CurrentTiming.Frame;
            if (this.FlyingBack)
            {
                if ((double)this.Position.Y > (double)this.Npc.Position.Y)
                {
                    return;
                }
                this.Position      = this.Npc.Position;
                this.CurrentAction = NpcAction.Land;
                this.flySpeed      = Vector2.Zero;
                this.UpdateAction();
                this.FlyingBack = false;
                this.flyRight   = new Vector3?();
            }
            else
            {
                if (this.CameraManager.Frustum.Contains(new BoundingBox(this.Position - Vector3.One, this.Position + Vector3.One)) != ContainmentType.Disjoint)
                {
                    return;
                }
                if (this.MayComeBack)
                {
                    this.OwlInvisible  = true;
                    this.MayComeBack   = false;
                    this.CurrentAction = NpcAction.Idle;
                    this.flySpeed      = Vector2.Zero;
                    this.flyRight      = new Vector3?();
                    this.UpdateAction();
                }
                else
                {
                    ServiceHelper.RemoveComponent <NpcState>(this);
                }
            }
        }
Exemple #35
0
 private void Turn()
 {
   this.LookingDirection = FezMath.GetOpposite(this.LookingDirection);
   this.UpdateRotation();
   this.CurrentAction = this.CanWalk ? NpcAction.Walk : NpcAction.Idle;
 }