コード例 #1
0
    public void ResetCreatNpcInfo(NpcState type)
    {
        //Debug.Log("ResetCreatNpcInfo -> type =================== " + type);
        switch (type)
        {
        case NpcState.ZhanChe:
        {
            m_ZhanCheJPBossData.IsCreatZhanChe = false;
            m_ZhanCheRulerData.Reset();
            break;
        }

        case NpcState.JPBoss:
        {
            m_ZhanCheJPBossData.IsCreatJPBoss = false;
            m_JPBossRulerData.Reset();
            break;
        }

        case NpcState.SuperJPBoss:
        {
            m_ZhanCheJPBossData.IsCreatSuperJPBoss = false;
            break;
        }
        }
    }
コード例 #2
0
        protected virtual void FixedUpdate()
        {
            if (currentHp > 0)
            {
                if (playerHead != null)
                {
                    if (hostileToPlayer)
                    {
                        state = Vector3.Distance(transform.position, new Vector3(playerHead.position.x, playerBoundary.position.y, playerHead.position.z)) > 1.5f ? NpcState.MoveToPlayer : NpcState.FightingPlayer;
                    }
                    else
                    {
                        state = NpcState.Idle;
                    }

                    switch (state)
                    {
                    case NpcState.FightingPlayer:
                        FightingPlayer();
                        break;

                    case NpcState.MoveToPlayer:
                        MoveToPlayer();
                        break;
                    }
                }

                SetAnimatorMovementSpeed();
            }
        }
コード例 #3
0
        private void TryToPlay(NpcActor owner)
        {
            int      seed  = RandomHelper.Range((int)NpcState.Sleep, (int)NpcState.Count);
            NpcState state = (NpcState)seed;

            switch (state)
            {
            case NpcState.Sleep:
                owner.StateMachine.ChangeState(new NpcStateSleep());
                break;

            case NpcState.PlayPhone:
                owner.StateMachine.ChangeState(new NpcStatePlayPhone());
                break;

            case NpcState.Internet:    //如果转变为上网状态时老板恰好在,就恢复到工作状态,重新计算
                if (owner.IsBossShow)
                {
                    m_time = 0;
                }
                else
                {
                    owner.StateMachine.ChangeState(new NpcStateInternet());
                }


                break;
            }
        }
コード例 #4
0
        private HashSet <Sprite> DeserializeInteriorObjects(List <InteriorObjectSerialized> interiorObjsSaved, Interior interior)
        {
            HashSet <Sprite> ret = new HashSet <Sprite>();

            foreach (InteriorObjectSerialized objSave in interiorObjsSaved)
            {
                Sprite sp = null;
                if (objSave.groundObj)
                {
                    OnGroundState ogs = (OnGroundState)objSave.saveState;
                    sp           = DeserializeModel(ogs.objKey, objSave.saveState);
                    sp.location  = ogs.location;
                    sp.regionKey = ogs.region;
                }
                else if (objSave.npcObj)
                {
                    NpcState npcs = (NpcState)objSave.saveState;
                    Npc      npc  = (Npc)DeserializeModel(npcs.objKey, npcs);
                    npc.location      = npcs.location;
                    npc.inventory     = DeserializeInventory(npcs.inventory);
                    npc.regionKey     = npcs.region;
                    npc.onShip        = npcs.onShip;
                    npc.health        = npcs.health;
                    npc.npcInInterior = interior;
                    sp = npc;
                }
                ret.Add(sp);
            }
            return(ret);
        }
コード例 #5
0
ファイル: NPC.cs プロジェクト: idalexcan/Zombojstan
        IEnumerator ChangeVar()
        {
            for (; ;)
            {
                state = (NpcState)Random.Range(1, 3);
                switch (state)
                {
                case NpcState.idle:
                    break;

                case NpcState.moving:
                    transform.eulerAngles = new Vector3(0, Random.Range(0, 360), 0);
                    break;

                case NpcState.rotating:
                    float rot = 0;
                    while (rot == 0)
                    {
                        rot = Rand.rand.Next(-1, 2);
                    }
                    break;
                }
                yield return(new WaitForSeconds(5));
            }
        }
コード例 #6
0
        private async Task saveNpcUserState(NpcState state)
        {
            var serializedState = Newtonsoft.Json.JsonConvert.SerializeObject(state);
            var cacheKey        = buildCacheKey(state);
            var setCacheKey     = buildSetCacheKey(state);

            try
            {
                if (state.UniqueId != null)
                {
                    await redis.GetDatabase().SetAddAsync(setCacheKey, state.UniqueId);
                }


                if (!await redis.GetDatabase().StringSetAsync(cacheKey, serializedState, state.Expiration - DateTime.UtcNow))
                {
                    throw new RedisException("Couldn't save " + cacheKey);
                }
            }
            catch (Exception ex)
            {
                await redis.GetDatabase().KeyDeleteAsync(cacheKey);

                await redis.GetDatabase().SetRemoveAsync(setCacheKey, state.UniqueId);

                throw new CritterException("Something went wrong! Try your NPC interaction again.",
                                           $"Failed to save value {serializedState} for NPC {state.NpcId}! NPCs don't work now!", System.Net.HttpStatusCode.InternalServerError, ex);
            }
        }
コード例 #7
0
ファイル: TadpoleFlock.cs プロジェクト: vinhphu3000/MurmurG
    void NpcStateManager()
    {
        npcDirection = player.position - goalPrefab.transform.position;
        angle        = Vector3.Angle(npcDirection, head.up);

        // reset NPC if too far outside of tank
        if (Vector3.Distance(transform.position, goalPrefab.transform.position) >= tankSize + 2)
        {
            goalPrefab.transform.position = transform.position;
        }

        if (Vector3.Distance(player.position, goalPrefab.transform.position) < npcViewRange &&
            (angle < npcViewAngle || activeNpcState == NpcState.PURSUE))

        {
            if (npcDirection.magnitude > npcEngageMagnitude)
            {
                activeNpcState = NpcState.PURSUE;
            }
            else
            {
                activeNpcState = NpcState.ATTACK;
            }
        }
        else
        {
            activeNpcState = NpcState.PATROL;
        }
    }
コード例 #8
0
 //转换NPC动画状态
 public void PlayInState(NpcState aimState)
 {
     if (aimState == NpcState.IDLE)
     {
         playIdle();
     }
     else if (aimState == NpcState.TALK)
     {
         playTalk();
     }
     else if (aimState == NpcState.WALK)
     {
         playWalk();
     }
     else if (aimState == NpcState.RUN)
     {
         playRun();
     }
     else if (aimState == NpcState.WOUND)
     {
         playWoundAndDead();
     }
     else if (aimState == NpcState.ATTACK1)
     {
         playAttack();
     }
     else if (aimState == NpcState.ATTACK2)
     {
         //playAttack2();
     }
     else if (aimState == NpcState.ATTACK3)
     {
         //playAttack3();
     }
 }
コード例 #9
0
ファイル: NPC.cs プロジェクト: captainzonks/Udemy-RPG
        private IEnumerator KnockCo(Rigidbody2D myRigidbody, float knockTime)
        {
            yield return(new WaitForSeconds(knockTime));

            myRigidbody.velocity = Vector2.zero;
            currentState         = NpcState.Idle;
            myRigidbody.velocity = Vector2.zero;
        }
コード例 #10
0
        public void Perish()
        {
            IsDead = true;
            State  = NpcState.Dead;
            int randAnim = RandomProvider.Get().Next(StateActions[NpcState.Dead].Length);

            Animation = AnimationStorage.GetSequenceIdBySequenceName(Model, StateActions[NpcState.Dead][randAnim].Item1);
        }
コード例 #11
0
 public void Damage(Vector3 impact)
 {
     FollowerManager.Followers.Remove(this);
     _state                            = NpcState.Dying;
     _agent.enabled                    = false;
     _rigidbody.isKinematic            = false;
     _rigidbody.collisionDetectionMode = CollisionDetectionMode.Continuous;
     _rigidbody.AddForce(impact, ForceMode.Impulse);
 }
コード例 #12
0
        public void AttachState(NpcState State)
        {
            if (IsNegativeState(State) && IsState(NpcState.God))
            {
                return;
            }

            State_ |= (int)State;
        }
コード例 #13
0
        public void DetachState(NpcState State)
        {
            if (State == NpcState.Dizzy)
            {
                Master.Actor.ChangeToIdleState();
            }

            State_ &= (~(int)State);
        }
コード例 #14
0
        public async Task SaveNpcState(NpcState state)
        {
            if (state.Expiration != null && state.Expiration >= DateTime.UtcNow)
            {
                await DbRepo.SaveNpcState(state);
            }

            await CacheRepo.SaveNpcState(state);
        }
コード例 #15
0
ファイル: NpcController.cs プロジェクト: trdillon/ravar
        private void OnDialogFinish(string npcName)
        {
            if (npcName != _name)
            {
                return;
            }

            _idleTimer = 0f;
            _state     = NpcState.Idle;
        }
コード例 #16
0
 /// <summary>
 /// 根据npc当前的状态获取到对应的文本
 /// </summary>
 /// <param name="npcState"> npc状态</param>
 /// <param name="ID">npcID</param>
 /// <param name="talkSystem">对话系统示例</param>
 public void GetTxt(NpcState npcState, int ID, TalkSystem talkSystem)
 {
     talkSystem.InitTalk();
     path     = Application.streamingAssetsPath + "/TalkTxt/" + ID + "/" + npcState + "/1.json";
     showTxts = JsonMapper.ToObject <ShowTxt[]>(JsonMapper.ToJson(JsonReader.ReadJson(path)["ShowTxt"]));
     for (int i = 0; i < showTxts.Length; i++)
     {
         SaveTalkTxt.GetInstance().dic.Add(i + 1, showTxts[i]);
     }
 }
コード例 #17
0
    private void Update()
    {
        direction = target.position.With(y: transform.position.y) - transform.position;
        angle     = Vector3.Angle(direction, transform.forward);

        if (direction.magnitude < 0.1)
        {
            sightAngle = nearSightAngle * 0.5f;
        }
        else if (direction.magnitude < nearSightDist)
        {
            sightAngle = Mathf.Lerp(nearSightAngle, farSightAngle, direction.magnitude / nearSightDist) * 0.5f;
        }
        else
        {
            sightAngle = farSightAngle * 0.5f;
        }

        if (direction.magnitude < visibleDist && angle < sightAngle)
        {
            transform.rotation = Quaternion.Slerp(transform.rotation,
                                                  Quaternion.LookRotation(direction),
                                                  rotationSpeed * Time.deltaTime);

            if (direction.magnitude > shootDist)
            {
                if (State != NpcState.Chasing)
                {
                    anim.SetTrigger("isRunning");
                    State = NpcState.Chasing;
                }
            }
            else
            {
                if (State != NpcState.Attacking)
                {
                    anim.SetTrigger("isShooting");
                    State = NpcState.Attacking;
                }
            }
        }
        else
        {
            if (State != NpcState.Idle)
            {
                anim.SetTrigger("isIdle");
                State = NpcState.Idle;
            }
        }

        if (State == NpcState.Chasing)
        {
            transform.Translate(0, 0, Time.deltaTime * speed);
        }
    }
コード例 #18
0
    /// <summary>
    /// 获取npc预制.
    /// </summary>
    GameObject GetNpcPrefab(NpcState type, SpawnPointState pointState)
    {
        GameObject[] npcPrefabGp = null;
        switch (type)
        {
        case NpcState.ZhanChe:
        {
            if (pointState == SpawnPointState.Left)
            {
                npcPrefabGp = m_NpcData.L_ZhanChePrefabGp;
            }
            else if (pointState == SpawnPointState.Right)
            {
                npcPrefabGp = m_NpcData.R_ZhanChePrefabGp;
            }
            else if (pointState == SpawnPointState.Up)
            {
                npcPrefabGp = m_NpcData.U_ZhanChePrefabGp;
            }
            else if (pointState == SpawnPointState.Down)
            {
                npcPrefabGp = m_NpcData.D_ZhanChePrefabGp;
            }
            break;
        }

        case NpcState.JPBoss:
        {
            npcPrefabGp = m_NpcData.JPBossPrefabGp;
            break;
        }

        case NpcState.SuperJPBoss:
        {
            npcPrefabGp = m_NpcData.SuperJPBossPrefabGp;
            break;
        }
        }

        if (npcPrefabGp == null || npcPrefabGp.Length <= 0)
        {
            Debug.LogWarning("Unity: not find npc! type ================ " + type);
            return(null);
        }

        GameObject npcPrefab = null;
        int        rv        = Random.Range(0, 100) % npcPrefabGp.Length;

        npcPrefab = npcPrefabGp[rv];
        if (npcPrefab == null)
        {
            Debug.LogWarning("Unity: npcPrefab was null! rv ============ " + rv + ", type == " + type);
        }
        return(npcPrefab);
    }
コード例 #19
0
        public void ChangeState(NpcState s, Fsm fsm)
        {
            DebugUtils.Assert(fsm != null, "Can't translate to a null npc state!");

            currentFsm.OnExit();
            currentFsm = fsm;
            state      = s;

            DebugUtils.LogWarning(DebugUtils.Type.AI_Npc, string.Format("{0} {1} enter {2} state", npcType, id, state));
            currentFsm.OnEnter();
        }
コード例 #20
0
        protected void SetNpcState(NpcState npcState)
        {
            _state = npcState;

            var animationForNewState          = _datum.GetAnimationForState(npcState);
            var framesInNewStateAnimation     = animationForNewState.GetPlayerFacingAnimation().FrameCount;
            var frameTimeForNewStateAnimation = animationForNewState.AnimationFrameTime;

            _animationFrame      = Random.Range(0, framesInNewStateAnimation);
            _animationFrameTimer = Random.Range(0f, frameTimeForNewStateAnimation);
        }
コード例 #21
0
    private void Start()
    {
        dialog = DialogManager.Singleton.GetDialog(dialogName);

        if (dialog != null)
        {
            state        = new NpcState();
            state.npc    = this;
            dialog.state = state;
        }
    }
コード例 #22
0
ファイル: Npc.cs プロジェクト: wesleytdavies/Blastball
    //private Renderer npcRenderer;

    public void ChangeState(NpcState newState)
    {
        if (currentState != null)
        {
            currentState.Leave(this);
        }
        currentState = newState;
        if (currentState != null)
        {
            currentState.Enter(this);
        }
    }
コード例 #23
0
        //[TestMethod]
        public void Execute()
        {
            IronRubyScript script = new IronRubyScript();

            script.Content = @"m=new MoveAction(new MapPoint(0,2,2));";



            GameMap game = MapCreation(1000, 1000, 1, 0, 0);
            NpcType type = new NpcType();

            type.Description = "1";
            type.Name        = "1";
            MapActiveObject obj = new MapActiveObject(null, null, new MapSize(1, 1), MapDirection.East, MapArmorType.None, 100, 0);

            Npc      npc   = new Npc(type, obj);
            NpcState state = new NpcState(npc, game.Map, script, new Fraction(), new MapPoint(0, 1, 1));

            state.PerformAction();
            //npc.Position = game.Map.Levels[0].Cells[1,1];
            //Move move = new Move(new MapPoint(0, 1, 2), npc);
            //((NPCAction)move).perform(game.Map);
            //MapCreation(1000, 1000, 1, 0, 0);


            //SimpleObject obj= new SimpleObject();
            //obj.mas=new int[50000000];
            //Random rand = new Random();
            //for (int i = 0; i < obj.mas.Length; i++)
            //  obj.mas[i] = rand.Next(100000);

//            ScriptRuntime runtime = IronRuby.Ruby.CreateRuntime();
//            ScriptEngine _rubyEngine = runtime.GetEngine("Ruby");
//            ScriptScope _scope = _rubyEngine.CreateScope();
//            _scope.SetVariable("obj", obj);
//            DateTime time1 = DateTime.Now;
//            var result1 = _rubyEngine.Execute(@" mas=[]
//                                                 (0..obj.mas.size()-1).each do |x|
//                                                      if obj.mas[x]<100
//                                                          mas+= [obj.mas[x]]
//                                                       end
//                                                  end
//                                                 m1=mas ", _scope);
//            DateTime time2 = DateTime.Now;
//            var result2 = _rubyEngine.Execute(@"  obj.mas.find_all{|elem| elem<100}  ", _scope);
//            DateTime time3 = DateTime.Now;
//            var result3 = _rubyEngine.Execute(@"  obj.getless100()  ", _scope);
//            DateTime time4 = DateTime.Now;
//            var result4 = obj.getless100();
//            DateTime time5 = DateTime.Now;
//            var result5 = obj.mas.Where(x => x < 100).ToArray();
//            DateTime time6 = DateTime.Now;
        }
コード例 #24
0
        public NpcAnimationDatum GetAnimationForState(NpcState npcState)
        {
            foreach (var npcAnimationDatum in _animations)
            {
                if (npcAnimationDatum.NpcState == npcState)
                {
                    return(npcAnimationDatum);
                }
            }

            throw new Exception("Could not find NPC Animation for NPC state " + npcState);
        }
コード例 #25
0
        private List <InteriorObjectSerialized> SerializeInteriorObjects(List <Sprite> interiorObjs, Guid interiorId)
        {
            List <InteriorObjectSerialized> ret = new List <InteriorObjectSerialized>();

            foreach (Sprite obj in interiorObjs)
            {
                InteriorObjectSerialized ios = new InteriorObjectSerialized();
                if (obj is IPlayer)
                {
                    continue; // don't save player as part of interior state, player is done seperatly
                }
                if (obj is INPC)
                {
                    NpcState state = new NpcState();
                    Npc      npc   = (Npc)obj;
                    state.team            = npc.teamType;
                    state.location        = npc.location;
                    state.objKey          = npc.bbKey;
                    state.region          = npc.regionKey;
                    state.inventory       = SerializeInventory(npc.inventory);
                    state.onShip          = npc.onShip;
                    state.health          = npc.health;
                    state.npcInInteriorId = interiorId;

                    ios.npcObj    = true;
                    ios.saveState = state;
                    ret.Add(ios);
                }
                else
                {
                    OnGroundState ogs = new OnGroundState();
                    ogs.objKey   = obj.bbKey;
                    ogs.region   = obj.regionKey;
                    ogs.team     = TeamType.Gusto;
                    ogs.location = obj.location;

                    if (obj is IStorage)
                    {
                        Storage storage = (Storage)obj;
                        ogs.inventory = SerializeInventory(storage.inventory);
                    }
                    else if (obj is IContainer)
                    {
                        Container cont = (Container)obj;
                        ogs.inventory = SerializeInventory(cont.drops);
                    }
                    ios.groundObj = true;
                    ios.saveState = ogs;
                    ret.Add(ios);
                }
            }
            return(ret);
        }
コード例 #26
0
    // Use this for initialization
    void Start()
    {
        State = NpcState.FindingTarget;

        rb = gameObject.GetComponent <Rigidbody>();
        ForcePointLeftTransform  = transform.Find("ForcePointLeft");
        ForcePointRightTransform = transform.Find("ForcePointRight");
        ForcePointFrontTransform = transform.Find("ForcePointFront");
        ForcePointBackTransform  = transform.Find("ForcePointBack");

        _missile = transform.Find("Missile").gameObject;
    }
コード例 #27
0
    void Start()
    {
        m_NpcState        = NpcState.PATROL;
        m_NavMeshAgent    = GetComponent <NavMeshAgent>();
        m_CurrentWaypoint = 0;
        m_Animator        = GetComponent <Animator>();

        m_NavMeshAgent.updatePosition = false;
        m_NavMeshAgent.updateRotation = true;

        HandleAnimation();
    }
コード例 #28
0
        public void Initialize(long id, NpcData proto, FixVector3 p, FixVector3 r)
        {
            this.id = id;

            type = LogicUnitType.NPC;

            position = p;

            transform.position = p.vector3;
            transform.rotation = Quaternion.Euler(r.vector3);

            brithPosition  = p;
            brithDirection = r;
            hurtType       = AttackPropertyType.PhysicalAttack;

            npcProto       = proto;
            iconId         = -1;
            metaId         = proto.ID;
            modelId        = proto.ModelID;
            modelRadius    = ConvertUtils.ToLogicInt(proto.ModelRadius);
            npcType        = (NpcType)proto.NPCType;
            attackType     = (NpcAttackType)proto.StandardAttack;
            rebornInterval = ConvertUtils.ToLogicInt(proto.RebornInterval);
            physicasAttack = (int)proto.PhysicsAttack;
            armor          = (int)proto.Armor;
            magicResist    = (int)proto.MagicResist;
            speedFactor    = ConvertUtils.ToLogicInt(proto.Speed);
            healthRegen    = proto.HealthRegen;

            maxHp            = proto.Health;
            chaseArea        = ConvertUtils.ToLogicInt(proto.TargetDetectRange);
            maxChaseDistance = ConvertUtils.ToLogicInt(proto.MaxChaseDistance);
            emberOutPut      = proto.EmberOutPut;
            projectileId     = proto.ProjectileId;
            attackRange      = ConvertUtils.ToLogicInt(proto.AttackRange);
            killReward       = proto.KillReward;
            attackDuration   = ConvertUtils.ToLogicInt(proto.AttackDuration);
            attackHitTime    = ConvertUtils.ToLogicInt(proto.AttackHitDuration);
            fightInterval    = 1;

            hp     = maxHp;
            damage = physicasAttack;
            healthRecoverInterval = GameConstants.HP_RECOVERY_INTERVAL_MILLISECOND;

            InitializeState();
            InitializePathAgent();

            debuffHandler = new DebuffHandler();
            buffHandler   = new BuffHandler();

            state      = NpcState.IDLE;
            currentFsm = fsmIdle;
        }
コード例 #29
0
 public virtual void TakeDamage(float amount, bool soundOff)
 {
     if (damageable)
     {
         hostileToPlayer = true;
         state           = NpcState.MoveToPlayer;
         currentHp      -= amount;
         if (currentHp < 0)
         {
             OnDeath();
         }
     }
 }
コード例 #30
0
    void FleeTheParty(NpcState state)
    {
        if (state != NpcState.Angry)
        {
            return;
        }

        pickupTrigger.enabled = false;
        obstacle.enabled      = false;
        agent.enabled         = true;
        agent.SetDestination(houseEnterance.position);
        animator.ChangeAnimation(AnimationType.Walking);
    }
コード例 #31
0
 public void Perform(NpcState NpcState)
 {
 }
コード例 #32
0
ファイル: NPCController.cs プロジェクト: jchillerup/sadly
 // Use this for initialization
 void Start()
 {
     _playerController = Player.GetComponent<PlayerController>();
     Navigator = GetComponent<NPCNavigator>();
     AllNPCs.Add(this);
     _state = new IdleState(this);
 }
コード例 #33
0
ファイル: NPCController.cs プロジェクト: jchillerup/sadly
 protected virtual void ChangeNpcState(NpcState state)
 {
     Npc._state = state;
     Npc.Navigator.StopMoving();
 }
コード例 #34
0
ファイル: NPCController.cs プロジェクト: jchillerup/sadly
 protected override void ChangeNpcState(NpcState state)
 {
     base.ChangeNpcState(state);
     _conversationPartner._state = new IdleState(_conversationPartner);
 }
コード例 #35
0
ファイル: NpcAi.cs プロジェクト: keegantc/ocst
 public void SetState( NpcState state )
 {
     CurrentState = StateLookup[ state ];
 }
コード例 #36
0
 public void Perform(NpcState NpcState)
 {
     NpcState.MapState.RelocateActiveObject(NpcState.MapActiveObjectGuid, Target);
 }
コード例 #37
0
ファイル: NPCController.cs プロジェクト: jchillerup/sadly
 protected override void ChangeNpcState(NpcState state)
 {
 }
コード例 #38
0
ファイル: NPCController.cs プロジェクト: jchillerup/sadly
 protected override void ChangeNpcState(NpcState state)
 {
     base.ChangeNpcState(state);
     _conversationPartner._state = new IdleState(_conversationPartner);
     _conversationPartner.Navigator.StopMoving();
 }