Ejemplo n.º 1
1
        private static int CalcScore(IPlayerState state, Weather weather, int maxCard)
        {
            // winter -> drummer -> spring
            // winter makes everything worth 1
            // spring makes the global largest card worth +3

            // sum the normal cards & apply winter
            var score = state.Desk
                            .Where(card => !card.IsSpecial && card.HasValue)
                            .Sum(card => weather == Weather.Winter ? 1 : card.Value);

            if (IsDebugEnabled) log.Debug("Value card sum: " + score);

            // drummer
            if (state.Desk.FirstOrDefault(c => c.Kind == CardType.Drummer) != null)
            {
                score *= 2;

                if (IsDebugEnabled) log.Debug("With drummer: " + score);
            }

            // spring
            if (weather == Weather.Spring)
            {
                // apply spring
                var maxCardNum = state.Desk
                                    .Where(card => !card.IsSpecial && card.HasValue && card.Value == maxCard)
                                    .Count();

                score += maxCardNum * 3;

                if (IsDebugEnabled)
                {
                    log.Debug("Found {0} cards with maxValue {1}", maxCardNum, maxCard);
                    log.Debug("With spring: " + score);
                }
            }

            // special value cards (modifiers do not apply)
            score += state.Desk.Where(c => c.IsSpecial && c.HasValue).Sum(c => c.Value);

            if (IsDebugEnabled)
            {
                log.Debug("With specials: " + score);
                log.Debug("Scoring done.");
            }

            return score;
        }
    /// <summary>
    /// 造成伤害
    /// </summary>
    /// <param name="attackHurtStruct"></param>
    public override CalculateHurt.Result GiveAttackHurtStruct(AttackHurtStruct attackHurtStruct)
    {
        IPlayerState        iPlayerState        = GameState.Instance.GetEntity <IPlayerState>();
        IAttributeState     playerAttribute     = iPlayerState.GetResultAttribute();
        PhysicDefenseFactor physicDefenseFactor = new PhysicDefenseFactor()//物理防御系数
        {
            CoefficientRatioReducingDamageFactor = iPlayerState.SelfRoleOfRaceInfoStruct.physicDefenseToHurtRateRatio,
            ImmunityInjury = iPlayerState.SelfRoleOfRaceInfoStruct.physicQuickToHurtExemptRatio
        };
        MagicDefenseFactor magicDefenseFactor = new MagicDefenseFactor() //魔法防御系数
        {
            CoefficientRatioReducingDamageFactor = iPlayerState.SelfRoleOfRaceInfoStruct.magicDefenseToHurtRateRatio
        };

        CalculateHurt.Result calculateHurtResult = CalculateHurt.Calculate(attackHurtStruct, playerAttribute, physicDefenseFactor, magicDefenseFactor);
        if (calculateHurtResult.hurt >= 0)
        {
            if (calculateHurtResult.hurt != 0)
            {
                //减血(因为这里是整合的属性,必须在外部将自身血量减去)
                iPlayerState.HP -= calculateHurtResult.hurt;
                //终端咏唱
                ISkillState iSkillState = GameState.Instance.GetEntity <ISkillState>();
                iSkillState.GetHitToSkillState();
                //手柄震动
                iPlayerState.SetVibration(0.1f, 0.7f, 0.7f);
            }
            //显示伤害
            base.ShowHurt(calculateHurtResult, iPlayerState.PlayerObj);
        }
        return(calculateHurtResult);
    }
Ejemplo n.º 3
0
    private void Update()
    {
        if (dead)
        {
            return;
        }

        // Check Ground
        RaycastHit hitInfo;

        if (groundgracetimer <= 0 && Physics.Raycast(transform.position, Vector3.down, out hitInfo, GROUNDCHECKDIST, ~LayerMask.NameToLayer("Terrain")))
        {
            grounded = true;
        }
        else
        {
            groundgracetimer--;
            grounded = false;
        }


        // State implementation
        var newState = state.HandleTransition(this);

        if (newState != null)
        {
            state.OnExit(this);
            state   = newState;
            actions = state.OnEnter(this);
        }

        state.HandleUpdate(this);
    }
 // Use this for initialization
 void Start()
 {
     startLocation = transform.position;
     ballReference = FindObjectOfType <Ball>();
     movement      = GetComponent <PlayerMove>();
     currentState  = sPlayerWait;
 }
    /// <summary>
    /// Kills player. Disabling collider and setting HP to a specific value.
    /// </summary>
    public void KillPlayer()
    {
        //tell the game manager someone died.
        if (playerStats.team == GameManager.Instance.teams["Right"])
        {
            GameManager.Instance.rightTeamDeath++;
        }
        else
        {
            GameManager.Instance.leftTeamDeath++;
        }

        //set refernce bool
        dead = true;

        //set health to a safer value.
        playerStats.currentHealth = 0;

        //Halt any movement from the player.
        StopMovement();

        //ensure state is dead. because due dilligence
        currentState = sPlayerDead;

        //disable Collider so that nothing hits teh dead player.
        GetComponent <CircleCollider2D>().enabled = false;
    }
    /// <summary>
    /// Revives player and sets health to a given % of their maximum.
    /// </summary>
    /// <param name="currentHeathPercent">% (1-100) of their maximum health a player should be revived with</param>
    public void RevivePlayer(float currentHeathPercent)
    {
        //tell the game manager that somone was revived.
        if (playerStats.team == GameManager.Instance.teams["Right"])
        {
            GameManager.Instance.rightTeamDeath++;
        }
        else
        {
            GameManager.Instance.leftTeamDeath++;
        }

        dead = false;

        //if the health % are outside of bounds correct them
        if (currentHeathPercent > 100)
        {
            currentHeathPercent = 100;
        }
        else if (currentHeathPercent < 1)
        {
            currentHeathPercent = 1;
        }

        //set player's health to be a specified % of their max.
        playerStats.currentHealth = playerStats.maxHealth / (currentHeathPercent / 100);

        //turn back on player collider.
        GetComponent <CircleCollider2D>().enabled = true;

        //reset the state tree.
        currentState = sPlayerWait;
        sPlayerWait.SetCurrentWait(reviveWaitTime);
    }
Ejemplo n.º 7
0
        public ITurn ChooseTurn(IPlayerState playerState, IPlayerState opponentState)
        {
            var canSwitchNeuromon = playerState.InactiveNeuromon.Any(n => !n.IsDead);

            var validTurnTypes = new List<int>
            {
                AttackTurnType
            };

            var sb = new StringBuilder();
            sb.AppendLine("1: Attack");

            if (canSwitchNeuromon)
            {
                sb.AppendLine("2: Change Neuromon");
                validTurnTypes.Add(ChangeNeuromonTurnType);
            }

            Console.WriteLine(sb.ToString());

            ITurn selectedTurn = null;
            var turnType = ReadInputUntilValid(input => validTurnTypes.Contains(input));

            if (turnType == AttackTurnType)
            {
                selectedTurn = ChooseAttack(playerState.ActiveNeuromon);
            }
            else if (turnType == ChangeNeuromonTurnType && canSwitchNeuromon)
            {
                selectedTurn = new SwitchActiveNeuromon(SelectActiveNeuromon(playerState, opponentState));
            }

            return selectedTurn;
        }
Ejemplo n.º 8
0
        public Neuromon SelectActiveNeuromon(IPlayerState playerState, IPlayerState opponentState)
        {
            Neuromon newActiveNeuromon;
            bool validSelection;

            var otherNeuromon = playerState.InactiveNeuromon;

            do
            {
                Console.WriteLine("Choose Neuromon:");

                var neuromonIndex = ReadInputUntilValid(input => input <= otherNeuromon.Count() && input > 0, "Invalid Neuromon Selection!");

                newActiveNeuromon = otherNeuromon[neuromonIndex - 1];

                validSelection = !newActiveNeuromon.IsDead;

                if (!validSelection)
                {
                    Console.WriteLine($"Cannot choose {newActiveNeuromon.Name} as they are dead!");
                }
            } while (!validSelection);

            return newActiveNeuromon;
        }
Ejemplo n.º 9
0
 private void IPlayerState_Changed(IPlayerState arg1, string arg2)
 {
     if (string.Equals(arg2, GameState.Instance.GetFieldName <IPlayerState, bool>(temp => temp.SpriteChanged)))
     {
         spriceText.text = playerState.Sprice.ToString();
     }
 }
Ejemplo n.º 10
0
        public void UseItem(ILink player)
        {
            PlayerCharacter = (IPlayer)player;
            firingState     = PlayerCharacter.CurrentState;

            if (firingState == PlayerCharacter.facingDownAttack)
            {
                Position       = new Vector2(PlayerCharacter.X + FIVE * Global.Var.SCALE, PlayerCharacter.Y + TEN * Global.Var.SCALE);
                swordDirection = Direction.DOWN;
                currentRect    = new Vector2(SEVEN * Global.Var.SCALE, Global.Var.TILE_SIZE * Global.Var.SCALE);
            }
            else if (firingState == PlayerCharacter.facingUpAttack)
            {
                Position       = new Vector2(PlayerCharacter.X + SIX * Global.Var.SCALE, PlayerCharacter.Y - TEN * Global.Var.SCALE);
                swordDirection = Direction.UP;
                currentRect    = new Vector2(SEVEN * Global.Var.SCALE, Global.Var.TILE_SIZE * Global.Var.SCALE);
            }
            else if (firingState == PlayerCharacter.facingLeftAttack)
            {
                Position       = new Vector2(PlayerCharacter.X - FOUR * Global.Var.SCALE, PlayerCharacter.Y + FIVE * Global.Var.SCALE);
                swordDirection = Direction.LEFT;
                currentRect    = new Vector2(Global.Var.TILE_SIZE * Global.Var.SCALE, SEVEN * Global.Var.SCALE);
            }
            else if (firingState == PlayerCharacter.facingRightAttack)
            {
                Position       = new Vector2(PlayerCharacter.X + TEN * Global.Var.SCALE, PlayerCharacter.Y + FIVE * Global.Var.SCALE);
                swordDirection = Direction.RIGHT;
                currentRect    = new Vector2(Global.Var.TILE_SIZE * Global.Var.SCALE, SEVEN * Global.Var.SCALE);
            }
            itemUse = true;
        }
Ejemplo n.º 11
0
		private void RefreshFromDedicatedServer()
		{
			if (SteamClientDSConfig.Server == null)
			{
				Debug.LogError("There is no server information stored on this client.");
				return;
			}
			for (int i = this._grid.transform.childCount - 1; i >= 0; i--)
			{
				UnityEngine.Object.Destroy(this._grid.GetChild(i).gameObject);
			}
			SteamClientDSConfig.playerCount = 0;
			int nMaxPlayers = SteamClientDSConfig.Server.m_nMaxPlayers;
			IPlayerState state = LocalPlayer.Entity.GetState<IPlayerState>();
			CoopServerInfo instance = CoopServerInfo.Instance;
			NetworkArray_Integer clients = instance.state.Clients;
			NetworkArray_String playerNames = instance.state.PlayerNames;
			for (int j = 0; j < playerNames.Length; j++)
			{
				if (!playerNames[j].NullOrEmpty())
				{
					SteamClientDSConfig.playerCount++;
					int connectionId = clients[j - 1];
					this.AddPlayerRow(playerNames[j], connectionId, CoopSteamClientStarter.IsAdmin && playerNames[j] != LocalPlayer.State.name);
				}
			}
			this.UpdatePlayerCountText(SteamClientDSConfig.playerCount + "/" + SteamClientDSConfig.Server.m_nMaxPlayers);
		}
Ejemplo n.º 12
0
 public void Enter(PlayerMachine.Data playerControll)
 {
     data                 = playerControll;
     data.targets         = new List <GameObject>();
     data.agent.isStopped = true;
     result               = null;
 }
Ejemplo n.º 13
0
 public void UseItem(IPlayer player)
 {
     PlayerCharacter = player;
     firingState     = PlayerCharacter.CurrentState;
     if (firingState == PlayerCharacter.facingDownItem)
     {
         Position       = new Vector2(PlayerCharacter.X + 5 * Global.Var.SCALE, PlayerCharacter.Y + 10 * Global.Var.SCALE);
         arrowDirection = Direction.DOWN;
         currentRect    = new Vector2(5 * Global.Var.SCALE, 16 * Global.Var.SCALE);
     }
     else if (firingState == PlayerCharacter.facingUpItem)
     {
         Position       = new Vector2(PlayerCharacter.X + 6 * Global.Var.SCALE, PlayerCharacter.Y - 10 * Global.Var.SCALE);
         arrowDirection = Direction.UP;
         currentRect    = new Vector2(5 * Global.Var.SCALE, 16 * Global.Var.SCALE);
     }
     else if (firingState == PlayerCharacter.facingLeftItem)
     {
         Position       = new Vector2(PlayerCharacter.X - 4 * Global.Var.SCALE, PlayerCharacter.Y + 5 * Global.Var.SCALE);
         arrowDirection = Direction.LEFT;
         currentRect    = new Vector2(16 * Global.Var.SCALE, 5 * Global.Var.SCALE);
     }
     else if (firingState == PlayerCharacter.facingRightItem)
     {
         Position       = new Vector2(PlayerCharacter.X + 10 * Global.Var.SCALE, PlayerCharacter.Y + 5 * Global.Var.SCALE);
         arrowDirection = Direction.RIGHT;
         currentRect    = new Vector2(16 * Global.Var.SCALE, 5 * Global.Var.SCALE);
     }
     itemUse = true;
 }
        private Player createPlayer(int i_PlayerId, SpaceShipConfiguration i_SpaceShipConfiguration, IPlayerState i_PlayerState)
        {
            Player player = new Player(Screen, i_SpaceShipConfiguration, i_PlayerId, i_PlayerState);
            player.PlayerLost += onPlayerLost;

            return player;
        }
Ejemplo n.º 15
0
    public void Action()
    {
        if (data.points >= data.cost && data.agent.isStopped && canAttack)
        {
            if (data.freeMove >= data.distance)
            {
                data.freeMove -= data.distance;
            }
            else
            {
                data.freeMove = (1 + (int)(data.distance / data.character.currentStats.Battle.move)) * data.character.currentStats.Battle.move - data.distance;
            }
            if (data.freeMove < 0)
            {
                data.freeMove = 0;
            }
            else
            {
                data.freeMove = (float)Math.Round(data.freeMove, 1);
            }

            data.agent.isStopped = false;
            data.points         -= data.cost;
            endAction            = true;
            result = new IPS_Attack();
        }
    }
    void Start()
    {
        dj2D = GetComponent <DistanceJoint2D>();
        rb2D = GetComponent <Rigidbody2D>();

        currentState = walkingState;
    }
Ejemplo n.º 17
0
        public new IPlayerState HandleTransition(PlayerCharacter player)
        {
            IPlayerState baseTransition = base.HandleTransition(player);

            if (baseTransition != null)
            {
                return(baseTransition);
            }

            if (Input.GetButtonDown("Aim") || Input.GetAxis("AimAxis") > 0)
            {
                return(new ShooterState());
            }
            if (Input.GetButtonDown("Jump"))
            {
                return(new JumpState());
            }
            if (Input.GetButton("Attack"))
            {
                return(new AttackState());
            }
            if (Input.GetButtonDown("Dash"))
            {
                return(new DashState());
            }
            return(null);
        }
Ejemplo n.º 18
0
    void DrawAreaAttack()
    {
        List <Vector3> Vectors = new List <Vector3>();
        float          scale   = 0.02f;
        float          Range   = item.AreaRange / MissionController.multiplyDistance;

        for (float i = 0; i < 2 * Mathf.PI; i += scale)
        {
            float      x      = Range * Mathf.Cos(i) + data.target.x;
            float      z      = Range * Mathf.Sin(i) + data.target.z;
            Vector3    pos    = new Vector3(x, data.target.y, z);
            Vector3    result = pos;
            RaycastHit hit;
            if (Physics.Raycast(result, (-1) * Vector3.up, out hit))
            {
                result = hit.point;
            }
            result.y += 0.05f;
            Vectors.Add(result);
        }
        data.lineRender[2].positionCount = Vectors.Count;
        data.lineRender[2].SetPositions(Vectors.ToArray());
        data.lineRender[2].enabled = true;
        ActiveCollider();
    }
 void Start()
 {
     iPlayerState = GameState.Instance.GetEntity <IPlayerState>();
     levelData    = DataCenter.Instance.GetMetaData <LevelData>();
     GameState.Instance.Registor <IPlayerState>(IPlayerStateChanged);
     SetExperience();
 }
 /// <summary>
 /// 玩家状态发生变化
 /// </summary>
 /// <param name="iPlayerState"></param>
 /// <param name="fieldName"></param>
 private void IPlayerStateChanged(IPlayerState iPlayerState, string fieldName)
 {
     if (string.Equals(fieldName, GameState.Instance.GetFieldName <IPlayerState, int>(temp => temp.Experience)))//经验发生变化
     {
         SetExperience();
     }
 }
Ejemplo n.º 21
0
 // Use this for initialization
 void Start()
 {
     currentState = vulnerableState;
     health       = 8;
     invincible   = false;
     once         = false;
 }
Ejemplo n.º 22
0
        public ITurn ChooseTurn(IPlayerState playerState, IPlayerState opponentState)
        {
            var move = _rand.Next(0, 4);
            var selectedMove = playerState.ActiveNeuromon.MoveSet[move];

            return new Attack(selectedMove);
        }
Ejemplo n.º 23
0
        private static bool CheckAttackIntention(IIntention intention, IPlayerState playerState, IActor target)
        {
            var attackIntention = (Intention <AttackTask>)intention;
            var attackTask      = attackIntention.TaskFactory(playerState.ActiveActor.Actor);

            return(attackTask.Target == target);
        }
Ejemplo n.º 24
0
 public PlayerState()
 {
     infAmmo      = new InfinityAmmoState(this);
     fast         = new FastState(this);
     slow         = new SlowState(this);
     currectState = slow;
 }
Ejemplo n.º 25
0
 private void Start()
 {
     reticlePos = new Vector2(Screen.width / 2, Screen.height / 2);
     state      = new MeleeState();
     health     = maxHealth;
     actions    = PlayerActions.GetInstance();
 }
Ejemplo n.º 26
0
        public ITurn ChooseTurn(IPlayerState playerState, IPlayerState opponentState)
        {
            _brain.ResetState();

            var serializedState = _gameStateSerializer.Serialize(playerState, opponentState);
            _brain.InputSignalArray.CopyFrom(serializedState, 0);

            _brain.Activate();

            var rawOutput = new double[_brain.OutputCount];
            _brain.OutputSignalArray.CopyTo(rawOutput, 0);

            var neatAiTurnChoices = _gameStateSerializer.Deserialize(rawOutput).ToList();

            var orderedChoices = neatAiTurnChoices.OrderByDescending(choice => choice.Weight);

            var validTurnTypes = DetermineValidTurnTypes(playerState).ToList();

            ITurn validTurn = null;
            foreach (var turnChoice in orderedChoices)
            {
                if (TryParseValidTurn(turnChoice, playerState, validTurnTypes, out validTurn))
                {
                    break;
                }
            }

            if (validTurn == null)
            {
                throw new Exception("Neat Ai Turn Choice is invalid");
            }

            return validTurn;
        }
Ejemplo n.º 27
0
        public Neuromon SelectActiveNeuromon(IPlayerState playerState, IPlayerState opponentState)
        {
            var aliveNeuromon = playerState.AllNeuromon.Where(n => !n.IsDead).ToList();

            var neuromonIndex = _rand.Next(0, aliveNeuromon.Count);
            return aliveNeuromon[neuromonIndex];
        }
Ejemplo n.º 28
0
        public override void OnOwner(PlayerCommand cmd, BoltEntity entity)
        {
            if (entity.isOwner)
            {
                IPlayerState     state      = entity.GetState <IPlayerState>();
                PlayerController controller = entity.GetComponent <PlayerController>();

                Vector3    pos;
                Quaternion look;

                // this calculate the looking angle for this specific entity
                PlayerCamera.instance.CalculateCameraAimTransform(entity.transform, state.pitch, out pos, out look);

                // display debug
                Debug.DrawRay(pos, look * Vector3.forward);

                using (var hits = BoltNetwork.RaycastAll(new Ray(pos, look * Vector3.forward), cmd.ServerFrame))
                {
                    for (int i = 0; i < hits.count; ++i)
                    {
                        var hit        = hits.GetHit(i);
                        var serializer = hit.body.GetComponent <PlayerController>();

                        if ((serializer != null) && (serializer.state.team != state.team))
                        {
                            serializer.ApplyDamage(controller.activeWeapon.damagePerBullet);
                        }
                    }
                }
            }
        }
 /// <summary>
 /// 初始化数据对象
 /// </summary>
 private void InitDataTarget()
 {
     keyContactData    = DataCenter.Instance.GetEntity <KeyContactData>();
     iGameState        = GameState.Instance.GetEntity <IGameState>();
     iPlayerState      = GameState.Instance.GetEntity <IPlayerState>();
     iInteractiveState = GameState.Instance.GetEntity <IInteractiveState>();
 }
        public ITurn ChooseTurn(IPlayerState playerState, IPlayerState opponentState)
        {
            var validTurns = DetermineValidTurnTypes(playerState);

            var turnType = TurnType.Attack;

            var allTurnsAreCurrentlyValid = _supportedTurnTypes.All(t => validTurns.Contains(t));

            var activeNeuromonRank = RankNeuromonChoice(playerState.ActiveNeuromon, opponentState.ActiveNeuromon);
            var inactiveNeuromonRanks = RankNeuromon(playerState.InactiveNeuromon.Where(n => !n.IsDead), opponentState.ActiveNeuromon);

            var betterActiveNeuromon =
                inactiveNeuromonRanks.Where(choice => choice.Value > activeNeuromonRank)
                    .OrderByDescending(choice => choice.Value)
                    .ToList();

            if (allTurnsAreCurrentlyValid && betterActiveNeuromon.Any())
            {
                turnType = _turnTypeRouletteWheel.Spin();
            }

            switch (turnType)
            {
                case TurnType.Attack:
                    return ChooseAttack(playerState);
                case TurnType.SwitchActiveNeuromon:
                    return new SwitchActiveNeuromon(betterActiveNeuromon.First().Key);
                default:
                    throw new Exception($"Unsupported turn type: {turnType}");
            }
        }
Ejemplo n.º 31
0
        private void OnEnable()
        {
            defaultPlayerAnimation = FindObjectOfType <DefaultPlayerAnimation>();
            variableJoystick       = FindObjectOfType <VariableJoystick>();

            currentState = defaultPlayerState;
        }
Ejemplo n.º 32
0
        public void UseItem(ILink player)
        {
            PlayerCharacter   = (Player)player;
            FiringStatePlayer = PlayerCharacter.CurrentState;
            Entity            = (IEntity)PlayerCharacter;

            if (FiringStatePlayer == PlayerCharacter.facingDownItem)
            {
                Position      = new Vector2(PlayerCharacter.X + FOUR * Global.Var.SCALE, PlayerCharacter.Y + Global.Var.TILE_SIZE * Global.Var.SCALE);
                FireDirection = Direction.DOWN;
            }
            else if (FiringStatePlayer == PlayerCharacter.facingUpItem)
            {
                Position      = new Vector2(PlayerCharacter.X + THREE * Global.Var.SCALE, PlayerCharacter.Y - TEN * Global.Var.SCALE);
                FireDirection = Direction.UP;
            }
            else if (FiringStatePlayer == PlayerCharacter.facingLeftItem)
            {
                Position      = new Vector2(PlayerCharacter.X - TEN * Global.Var.SCALE, PlayerCharacter.Y + FOUR * Global.Var.SCALE);
                FireDirection = Direction.LEFT;
            }
            else if (FiringStatePlayer == PlayerCharacter.facingRightItem)
            {
                Position      = new Vector2(PlayerCharacter.X + F_THIRTEEN_DOT_TWO * Global.Var.SCALE, PlayerCharacter.Y + FOUR * Global.Var.SCALE);
                FireDirection = Direction.RIGHT;
            }
            ItemUse   = true;
            PlayerUse = true;
            GoriyaUse = false;
        }
Ejemplo n.º 33
0
        public RightMovingPlayerSprite(Texture2D inTexture, IPlayerState inState, int damageFramesRemaining)
        {
            texture = inTexture;
            state   = inState;



            frames.AddLast(new Rectangle(34, 0, 16, 16));
            frames.AddLast(new Rectangle(51, 0, 16, 16));

            currentFrame = frames.First;

            damaged = 0;

            moving = false;
            if (damageFramesRemaining != 0)
            {
                damageFlash();
                //trim the list
                for (int i = 0; i < damageFramesRemaining; i++)
                {
                    damaged--;
                    state.SetDamaged(damaged);
                    frames.RemoveFirst();
                }
            }
        }
Ejemplo n.º 34
0
    /// <summary>
    /// 保存数据的携程
    /// </summary>
    /// <returns></returns>
    IEnumerator SavingEnumerator()
    {
        UIAction.isSaving = true;
        saveingImage.gameObject.SetActive(true);
        float        savingTime   = 0;
        IGameState   iGameState   = GameState.Instance.GetEntity <IGameState>();
        IPlayerState iPlayerState = GameState.Instance.GetEntity <IPlayerState>();
        PlayerState  playerState  = DataCenter.Instance.GetEntity <PlayerState>();

        playerState.Scene    = iGameState.SceneName;
        playerState.Location = iPlayerState.PlayerObj.transform.position + Vector3.up * 0.2f;
        //保存原来地形的遮罩图
        if (!string.IsNullOrEmpty(iGameState.SceneName))
        {
            playerState.SaveGetSceneMapMaskData(iGameState.SceneName);
        }
        DataCenter.Instance.Save(1);
        while (savingTime < 3)
        {
            savingTime += Time.deltaTime;
            yield return(null);

            saveingImage.transform.localEulerAngles = new Vector3
                                                      (
                saveingImage.transform.localEulerAngles.x,
                saveingImage.transform.localEulerAngles.y,
                saveingImage.transform.localEulerAngles.z + 180 * Time.deltaTime
                                                      );
        }
        UIAction.isSaving = false;
        saveingImage.gameObject.SetActive(false);
    }
 /// <summary>
 /// 监听角色状态更改(主要是装备)
 /// </summary>
 /// <param name="iPlayerState"></param>
 /// <param name="fieldName"></param>
 private void CallBackIPlayerStateState(IPlayerState iPlayerState, string fieldName)
 {
     if (!playerAnimator)
     {
         return;
     }
     //角色装备发生变化
     if (string.Equals(fieldName, GameState.Instance.GetFieldName <IPlayerState, bool>(temp => temp.EquipmentChanged)))
     {
         PlayerState playerState = DataCenter.Instance.GetEntity <PlayerState>();
         PlayGoods   playGoods   = playerState.PlayerAllGoods.Where(temp => temp.GoodsLocation == GoodsLocation.Wearing && temp.leftRightArms != null && temp.leftRightArms.Value == true).FirstOrDefault();
         if (playGoods != null)
         {
             EnumGoodsType enumGoodsType = playGoods.GoodsInfo.EnumGoodsType;
             //与1000相除求出剔除了具体类型后的上层一分类
             //然后与100求余计算出具体的武器分类
             //因为武器的分类是从10开始的因此减去10
             //动画的第一个分类留空为0表示空手,因此加1
             int num = (((int)enumGoodsType) / 1000) % 100 - 10 + 1;
             //如果是武器
             if (enumGoodsType > EnumGoodsType.Arms && enumGoodsType < EnumGoodsType.Arms + 100000)
             {
                 playerAnimator.SetFloat("WeaponType", num);
             }
             else //否则空手
             {
                 playerAnimator.SetFloat("WeaponType", 0);
             }
         }
         else
         {
             playerAnimator.SetFloat("WeaponType", 0);//0表示空手
         }
     }
 }
Ejemplo n.º 36
0
        public Player(Texture2D inTexture, Vector2 position, Texture2D inProjectiles, Sounds sounds)
        {
            texture     = inTexture;
            X           = (int)position.X;
            Y           = (int)position.Y;
            Rupees      = 25;
            attack      = false;
            projectiles = inProjectiles;
            state       = new LeftMovingPlayerState(texture, new Vector2(X, Y), this, inProjectiles);
            AttackCount = 0;
            Map         = false;
            Compass     = false;

            ObtainItem("Arrow");
            InitializeFromConstants();//initialize until changed



            SelectItem(1);

            invincible = false;
            maxHealth  = 12;
            health     = maxHealth;
            sound1     = sounds;
        }
    private void Awake()
    {
        m_PlayerController       = GameObject.FindObjectOfType <PlayerController>();
        m_PlayerPhysicsBehaviour = gameObject.AddComponent <PlayerPhysicsBehaviour>();
        m_PlayerData             = m_PlayerController.m_PlayerData;
        m_Input = m_PlayerController.m_InputControlles;
        m_GroundCheckBehaviour = GetComponent <GroundCheckBehaviour>();
        m_Animator             = GetComponentInChildren <Animator>();
        m_PlayerHitBoxSpawner  = GameObject.FindObjectOfType <PlayerHitBoxSpawner>();
        m_CanTurn            = true;
        m_CanJump            = true;
        m_CanChangeColor     = true;
        m_CanChangeCharacter = true;
        m_WasGrounded        = true;
        m_BoxCollider2D      = GetComponent <BoxCollider2D>();
        m_SpriteRenderer     = GetComponentInChildren <SpriteRenderer>();
        m_PlayerState        = new PlayerStandingBehaviour(this);

        m_OriginalColliderSize   = new Vector2(0.75f, 2.5f);
        m_OriginalColliderOffset = new Vector2(0f, -0.75f);

        m_CobaltBehaviour        = new CobaltBehaviour();
        m_CobaltData             = ScriptableObject.CreateInstance <CobaltData>();
        m_CobaltBulletController = GameObject.FindObjectOfType <CobaltBulletController>();
    }
Ejemplo n.º 38
0
        private static bool CheckUsePropIntention(IIntention intention, IPlayerState playerState, IProp usedProp)
        {
            var usePropIntention = (Intention <UsePropTask>)intention;
            var usePropTask      = usePropIntention.TaskFactory(playerState.ActiveActor.Actor);

            return(usePropTask.UsedProp == usedProp);
        }
Ejemplo n.º 39
0
        public void ChangeState(IPlayerState state)
        {
            _state.ExitState(this);
            _state = null; // delete old state (not sure if this works?)

            _state = state;
            _state.EnterState(this);
        }
 public Player(GameScreen i_GameScreen, SpaceShipConfiguration i_SpaceShipConfiguration, int i_PlayerId, IPlayerState i_PlayerState)
 {
     r_SpaceShip = new SpaceShip(i_GameScreen, i_SpaceShipConfiguration, i_PlayerId);
     ScoresBoard = new ScoresBoard(i_GameScreen, i_PlayerId, i_SpaceShipConfiguration.TextColor);
     r_SoulsBoard = new SoulsBoard(i_GameScreen, i_PlayerState, i_SpaceShipConfiguration.AssetName, i_PlayerId);
     r_SpaceShip.SpaceShipHit += spaceShipOnHit;
     r_SpaceShip.Died += spaceShipOnDie;
     r_SpaceShip.BulletCollided += bulletCollision;
 }
Ejemplo n.º 41
0
    /// <summary>
    /// adjusts the the players state according to his figures
    /// </summary>
    public void RefreshState()
    {
        int figuresOnGameOrStairField = FigureCtrl.GetFiguresOnRegularOrStairField(this).Count;
        int figuresOnGoalField = FigureCtrl.GetFiguresOnGoalField(this).Count;
        int figuresOnHomeField = FigureCtrl.GetFiguresOnHomeField(this).Count;

        if (figuresOnGoalField == FigureCtrl.NofFigures) State = new PlayerStateStateAllInGoal();
        else if (figuresOnGameOrStairField == 0) State = new PlayerStateAllAtHome();
        else State = new PlayerStateAtLeastOneOut();
    }
        public SoulsBoard(GameScreen i_GameScreen, IPlayerState i_PlayerState, string i_AssetName, int i_PlayerId)
            : base(i_GameScreen)
        {
            PlayerState = i_PlayerState;
            r_PlayerId = i_PlayerId;

            for (int i = 0; i < PlayerState.Lives; i++)
            {
                r_Sprites.Add(new SoulIcon(i_AssetName, i_GameScreen));
            }
        }
Ejemplo n.º 43
0
        public Neuromon SelectActiveNeuromon(IPlayerState playerState, IPlayerState opponentState)
        {
            var turn = ChooseTurn(playerState, opponentState) as SwitchActiveNeuromon;

            if (turn == null)
            {
                throw new Exception($"Chosen turn must be of type {typeof(Neuromon)}");
            }

            return turn.Neuromon;
        }
        public override void EndHand(EndHandContext context)
        {
            if (this.state.HandsPlayed > 0 && this.state.HandsPlayed % 100 == 0)
            {
                var bestRate = this.playerStates.Max(x => x.HandsSuccessRate);
                var bestState = this.playerStates.First(x => x.HandsSuccessRate == bestRate);
                this.state = bestState;
            }

            this.state.EndHand(context);
            base.EndHand(context);
        }
Ejemplo n.º 45
0
        public ShootingState(IPlayerState previousState)
        {
            _stateStack.Push(previousState);
            _stateStack.Push(this);

            IPlayerState[] arr = _stateStack.ToArray();

            string stackItems = "";
            foreach (IPlayerState p in arr)
                stackItems += p.ToString()  + "; ";

            Console.WriteLine(string.Format("Shooting stack (size: {0}): {1}", arr.Length, stackItems));
        }
        private static Neuromon ChooseNeuromon(IPlayerState playerState, IPlayerState opponentState)
        {
            var aliveNeuromon = playerState.InactiveNeuromon.Where(n => !n.IsDead).ToList();

            if (aliveNeuromon.Count == 1)
            {
                return aliveNeuromon.Single();
            }

            var rankedOrderedChoices = RankNeuromon(aliveNeuromon, opponentState.ActiveNeuromon)
                .OrderByDescending(choice => choice.Value);

            return rankedOrderedChoices.First().Key;
        }
        public IntelligentAiPlayerController(IPlayerState initialState)
        {
            _neuromonRouletteWheels = new Dictionary<Neuromon, RouletteWheel<Move>>();

            foreach (var neuromon in initialState.AllNeuromon)
            {
                var rouletteWheel = CreateMoveRouletteWheel(neuromon);
                _neuromonRouletteWheels.Add(neuromon, rouletteWheel);
            }

            _turnTypeRouletteWheel = CreateTurnTypeRouletteWheel();

            _supportedTurnTypes = new[] { TurnType.Attack, TurnType.SwitchActiveNeuromon };
        }
Ejemplo n.º 48
0
        private static IEnumerable<TurnType> DetermineValidTurnTypes(IPlayerState playerState)
        {
            if (playerState.ActiveNeuromon.IsDead)
            {
                return new[] { TurnType.SwitchActiveNeuromon };
            }

            var validMoves = new List<TurnType> { TurnType.Attack };

            if (playerState.InactiveNeuromon.Any(n => !n.IsDead))
            {
                validMoves.Add(TurnType.SwitchActiveNeuromon);
            }

            return validMoves;
        }
        public StateEvalOnHandsPlayer()
            : base()
        {
            this.playerStates = new IPlayerState[]
            {
                new SafeAllInState(),
                new RecklessAllInState(),
                new NormalPlayerState(),
                new AlwaysAllInProtectionState()
            };

            this.rand = new RandomGenerator();

            var randomIndex = this.rand.GetRandomInteger(0, this.playerStates.Length);

            this.state = this.playerStates[randomIndex];
        }
        public void EndGame(EndGameContext context)
        {
            this.totalGamesCount++;

            this.state.GamesPlayed++;
            if (context.WinnerName == this.Name)
            {
                this.state.GamesWon++;
            }

            if (this.totalGamesCount % this.stateEvaluationGamesCount == 0)
            {
                var bestSuccessRate = this.playerStates.Max(x => x.GamesSuccessRate);
                var bestState = this.playerStates.First(x => x.GamesSuccessRate == bestSuccessRate);
                this.state = bestState;
            }

            this.state.EndGame(context);
        }
Ejemplo n.º 51
0
        public void HandleInput(Input input)
        {
            IPlayerState temp = _state.HandleInput(this, input);

            if (temp != _state)
            {
                _state.ExitState(this);
                _state = null; // delete old state (not sure if this works?)
                _state = temp;
                _state.EnterState(this);
            }

            if (input == Input.Idle)
            {
                _state.TimePass(1);
                Console.WriteLine("Time has passed by 1");

            }
            if (input == Input.TimeFastForward)
            {
                _state.TimePass(10);
                Console.WriteLine("Time has passed by 10");
            }
        }
Ejemplo n.º 52
0
        /**
        * Input Format:
        * [n]       = Neuromon Health
        * [n + 1]   = Neuromon Type
        * [n + 2]   = M1 Damage
        * [n + 3]   = M1 Type
        * [n + 4]   = M2 Damage
        * [n + 5]   = M2 Type
        * [n + 6]   = M3 Damage
        * [n + 7]   = M3 Type
        * [n + 8]   = M4 Damage
        * [n + 9]   = M4 Type
        *
        * Total Inputs = Number of Neuromon * Data per Neuromon * Number of Players = n * 10 * 2 = 20n
        */
        public double[] Serialize(IPlayerState playerState, IPlayerState opponentState)
        {
            var inputSignals = new double[_numberOfInputs];
            var currentIndex = 0;

            SerializePlayerState(playerState, inputSignals, ref currentIndex);
            SerializePlayerState(opponentState, inputSignals, ref currentIndex);

            // TODO: Remove
            if (currentIndex != _numberOfInputs)
            {
                throw new Exception("Incorrect Serialize Length");
            }

            return inputSignals;
        }
Ejemplo n.º 53
0
        private static void SerializePlayerState(IPlayerState playerState, IList<double> inputSignals, ref int currentIndex)
        {
            SerializeNeuromon(playerState.ActiveNeuromon, inputSignals, ref currentIndex);

            foreach (var neuromon in playerState.InactiveNeuromon)
            {
                SerializeNeuromon(neuromon, inputSignals, ref currentIndex);
            }
        }
Ejemplo n.º 54
0
		public void SetState(IPlayerState state){
			this.state = state;
		}
Ejemplo n.º 55
0
		public PlayerStateContext ()
		{
			state = null;
		}
Ejemplo n.º 56
0
    void Start()
    {
        state = new StandingState();
        attackState = new IdleAttackState();
        animator = GetComponent<Animator>();
        AttackCollider.SetActive(false);
        health = GetComponent<Health>();
        controller = GetComponent<MoveController>();
        gravity = -(2 * jumpHeight) / Mathf.Pow(timeToJumpApex, 2) / 3;
        jumpVelocity = Mathf.Abs(gravity) * timeToJumpApex;
        print("Gravity: " + gravity + "  Jump Velocity: " + jumpVelocity);

        initialRegenTime = 6;
        regenTick = 2;

        knockBackResistance = 10;
        knockBackCounter = 0;
        knockBackReset = 0;

        flinchResistance = 10;
        flinchCounter = 0;
        flinchReset = 0;

        text = GameObject.Find("HealthText").GetComponent<Text>();
        text.text = text.GetComponent<Score>().modX(0).ToString();
        blink = false;
        blinkTime = 0;
    }
Ejemplo n.º 57
0
 private void HandleInput()
 {
     if (!disableInput)
     {
         IPlayerState newState = state.HandleInput(this);
         if (newState != null)
         {
             state.ExitState(this);
             state = newState;
             state.EnterState(this);
         }
         IAttack newAttackState = attackState.HandleInput(this);
         if (newAttackState != null)
         {
             attackState.ExitState(this);
             attackState = newAttackState;
             attackState.EnterState(this);
         }
     }
 }
Ejemplo n.º 58
0
    /*
    void Awake()
    {
        if (player == null)
        {
            player = gameObject;
        }else if(player != gameObject)
        {
            Destroy(gameObject);
        }
    }*/
    void Start()
    {
        state = new StandingState();
        attackState = new IdleAttackState();
        animator = GetComponent<Animator>();
        skillManager = gameObject.AddComponent<SkillManager>();
        AttackCollider.SetActive(false);
        health = GetComponent<Health>();
        controller = GetComponent<MoveController>();
        crowdControllable = GetComponent<CrowdControllable>();
        mana = GetComponent<Mana>();
        attack = GetComponentInChildren<DealDamage>();
        defense = GetComponent<Defense>();
        attackController = GetComponent<AttackController>();
        gravity = -(2 * jumpHeight) / Mathf.Pow(timeToJumpApex, 2);
        jumpVelocity = Mathf.Abs(gravity) * timeToJumpApex;
        audiosource = GetComponent<AudioSource>();

        initialRegenTime = 6;
        regenTick = 2;

        DontDestroyOnLoad(gameObject);

        skill[0] = null;
        skill[1] = null;
        skill[2] = null;
        skill[3] = null;
        threatLevel = damageDealt = 0;

        GetComponent<ID>().setTime(false);
        CCI = GameObject.Find("Main Process").GetComponentInChildren<Character_Class_Info>();
        si = GameObject.Find("Main Process").GetComponentInChildren<Skill_info>();
        Fully_Update();
    }
Ejemplo n.º 59
0
 public void ChangeState(IPlayerState state)
 {
     player.currentState = state;
     player.currentState.StartState(controller.velocity);
 }
 public IPlayerController CreatePlayer(IPlayerState initiaPlayerState)
 {
     return new NeatAiPlayerController(_brain, _gameStateSerializer);
 }