コード例 #1
0
    public override void AICalculate()
    {
        float distanceSqr = Vector2.SqrMagnitude((Vector2)PositionConvertor.GetWorldPositionFromActorTileIndex
                                                     (this.m_TargetPosition) - (Vector2)this.m_AIBehavior.transform.position);

        if (this.m_Target == null)
        {
            InvaderIdleState idleState = new InvaderIdleState(this.m_AIBehavior, false);
            this.m_AIBehavior.ChangeState(idleState);
        }
        else
        {
            if (distanceSqr <= this.CharacterAI.AttackBehavior.AttackScopeSqr)
            {
                BuildingBasePropertyBehavior property = this.m_Target.GetComponent <BuildingBasePropertyBehavior>();
                AttackState attackState;
                if (property == null)
                {
                    attackState = new InvaderAttackState(this.m_AIBehavior, new AITargetObject(this.m_Target, this.m_Target.transform.position), this.CharacterAI.AttackBehavior);
                }
                else
                {
                    attackState = new InvaderAttackState(this.m_AIBehavior,
                                                         new AITargetObject(this.m_Target, (Vector2)(PositionConvertor.GetWorldPositionFromActorTileIndex(this.m_TargetPosition))), this.CharacterAI.AttackBehavior);
                }
                this.m_AIBehavior.ChangeState(attackState);
            }
            else
            {
                base.AICalculate();
            }
        }
    }
コード例 #2
0
    public override void Initial()
    {
        if (!this.CharacterAI.BattleMapData.ActorCanPass(this.m_CurrentPosition.Row, this.m_CurrentPosition.Column))
        {
            TilePosition tp = this.CharacterAI.PreviousValidPosition;
            if (tp == null)
            {
                GameObject target = this.CharacterAI.BattleSceneHelper.GetNearestBuildingOfCategory(this.m_AIBehavior.transform.position, this.CharacterAI.FavoriteCategory);
                if (target != null)
                {
                    BuildingBasePropertyBehavior property = target.GetComponent <BuildingBasePropertyBehavior>();
                    tp = property.GetBuildingFirstActorPosition();
                }
            }

            if (tp != null)
            {
                InvaderFindOutState findOutState = new InvaderFindOutState(this.CharacterAI.BattleMapData, tp, this.m_AIBehavior);
                this.m_AIBehavior.ChangeState(findOutState);
            }
        }
        else
        {
            this.CharacterAI.PreviousValidPosition = this.m_CurrentPosition;
        }
        base.Initial();
    }
コード例 #3
0
    protected virtual void OnDead()
    {
        AudioController.Play(this.m_DeadSound);

        GameObject ruins = BattleObjectCache.Instance.RuinsObjectParent;
        BuildingBasePropertyBehavior property = this.GetComponent <BuildingBasePropertyBehavior>();

        if (this.m_DeadEffectPrefab1 != null)
        {
            GameObject deadEffect = GameObject.Instantiate(this.m_DeadEffectPrefab1) as GameObject;
            deadEffect.transform.position = property == null ? this.transform.position
                                : property.AnchorTransform.position;

            deadEffect.transform.parent = ruins.transform;
        }
        if (this.m_DeadEffectPrefab2 != null)
        {
            GameObject deadEffect = GameObject.Instantiate(this.m_DeadEffectPrefab2) as GameObject;
            deadEffect.transform.position = property == null ? this.transform.position
                                : property.AnchorTransform.position;

            deadEffect.transform.parent = ruins.transform;
        }

        foreach (GameObject go in this.m_DoNotDestoryGameObjects)
        {
            if (go.transform.IsChildOf(this.transform))
            {
                go.transform.parent = ruins.transform;
            }
        }

        GameObject.DestroyObject(this.gameObject);
    }
コード例 #4
0
    private void ShowTarget()
    {
        if (BattleEffectConfig.Instance.TargetEffectPrefab != null && this.CharacterAI.IsShowTarget)
        {
            BuildingBasePropertyBehavior property = this.m_Target.GetComponent <BuildingBasePropertyBehavior>();
            GameObject targetEffect = GameObject.Instantiate(BattleEffectConfig.Instance.TargetEffectPrefab) as GameObject;
            Vector3    offset       = targetEffect.transform.position;

            Vector3 targetEffectPosition = property == null ? this.m_Target.transform.position :
                                           property.AnchorTransform.position;
            targetEffect.transform.position = targetEffectPosition + offset;
            targetEffect.transform.parent   = BattleObjectCache.Instance.EffectObjectParent.transform;
        }
    }
コード例 #5
0
    private void SetNoWallBuildingToTarget()
    {
        foreach (GameObject item in this.m_TargetsObjects)
        {
            if (item != null)
            {
                BuildingBasePropertyBehavior property = item.GetComponent <BuildingBasePropertyBehavior>();
                TilePosition destination = property.GetBuildingFirstActorPosition();
                IgnoreTargetAndAttackScopeWeightStrategy findPathStrategy = new IgnoreTargetAndAttackScopeWeightStrategy(
                    this.CharacterAI.BattleMapData, destination.Row, destination.Column, this.CharacterAI.AttackBehavior.AttackScope);
                //KodoPathFindStrage findPathStrategy = new KodoPathFindStrage(
                //	this.CharacterAI.BattleMapData, destination.Row, destination.Column);

                List <TilePosition> aStarPath;
                List <TilePosition> linePath = AStarPathFinder.CalculatePathTile(findPathStrategy, this.CharacterAI.BattleMapData.ActorObstacleArray,
                                                                                 this.m_CurrentPosition, destination, out aStarPath);

                TilePosition endPoint       = linePath[linePath.Count - 1];
                GameObject   targetBuilding = this.CharacterAI.BattleMapData.GetBulidingObjectFromActorObstacleMap(endPoint.Row, endPoint.Column);
                if (targetBuilding != null)
                {
                    property = targetBuilding.GetComponent <BuildingBasePropertyBehavior>();
                    if (property != null)
                    {
                        if (BattleEffectConfig.Instance.TargetEffectPrefab != null && this.CharacterAI.IsShowTarget)
                        {
                            GameObject targetEffect = GameObject.Instantiate(BattleEffectConfig.Instance.TargetEffectPrefab) as GameObject;
                            Vector3    offset       = targetEffect.transform.position;

                            Vector3 targetEffectPosition = property.AnchorTransform.position;
                            targetEffect.transform.position = targetEffectPosition + offset;
                            targetEffect.transform.parent   = BattleObjectCache.Instance.EffectObjectParent.transform;
                        }

                        BombermanWalkState walkState = new BombermanWalkState(this.CharacterAI.BattleMapData, endPoint, this.m_AIBehavior, targetBuilding);
                        walkState.SetPath(linePath);
                        this.m_AIBehavior.ChangeState(walkState);
                        break;
                    }
                }
            }
        }
    }
コード例 #6
0
    private void FindTarget()
    {
        TilePosition currentPosition = PositionConvertor.GetActorTileIndexFromWorldPosition(this.m_AIBehavior.transform.position);

        if (!this.FindDefender(currentPosition))
        {
            GameObject target = null;
            target = this.CharacterAI.BattleSceneHelper.GetNearestBuildingOfCategory(this.m_AIBehavior.transform.position, this.CharacterAI.FavoriteCategory);
            if (target != null)
            {
                BuildingBasePropertyBehavior property = target.GetComponent <BuildingBasePropertyBehavior>();
                int          rID = BattleRandomer.Instance.GetRandomNumber(0, property.ActorObstacleList.Count);
                TilePosition tp  = property.ActorPosition + property.ActorObstacleList[rID];


                InvaderWalkState invaderWalkState = new InvaderWalkState(this.CharacterAI.BattleMapData,
                                                                         tp, this.m_AIBehavior, target);
                this.m_AIBehavior.ChangeState(invaderWalkState);
            }
        }
    }
コード例 #7
0
    public override void AICalculate()
    {
        if (this.m_IsFindInstantly || this.m_AIBehavior.CanTakeResponse)
        {
            CharacterAI ai = (CharacterAI)this.m_AIBehavior;

            TilePosition currentPosition = PositionConvertor.GetActorTileIndexFromWorldPosition(this.m_AIBehavior.transform.position);
            if (!BattleMapData.Instance.ActorCanPass(currentPosition.Row, currentPosition.Column))
            {
                GameObject         go       = BattleMapData.Instance.GetBulidingObjectFromActorObstacleMap(currentPosition.Row, currentPosition.Column);
                BuildingHPBehavior targetHP = go.GetComponent <BuildingHPBehavior>();
                if (targetHP != null)
                {
                    CharacterAttack attack = ai.AttackBehavior;
                    targetHP.DecreaseHP(attack.AttackValue, attack.AttackCategory);
                }

                KodoHPBehavior hp = this.m_AIBehavior.GetComponent <KodoHPBehavior>();
                hp.Bomb();
            }
            else
            {
                List <GameObject> targets = BattleSceneHelper.Instance.GetBuildingsOfCategory(ai.FavoriteCategory);
                if (targets.Count > 0)
                {
                    int        i        = BattleRandomer.Instance.GetRandomNumber(0, targets.Count);
                    GameObject targetGo = targets[i];
                    BuildingBasePropertyBehavior targetProperty = targetGo.GetComponent <BuildingBasePropertyBehavior>();
                    i = BattleRandomer.Instance.GetRandomNumber(0, targetProperty.ActorObstacleList.Count);
                    TilePosition targetTile     = targetProperty.ActorPosition + targetProperty.ActorObstacleList[i];
                    Vector2      targetPosition = PositionConvertor.GetWorldPositionFromActorTileIndex(targetTile);

                    CrazyKodoWalkState walkState = new CrazyKodoWalkState(this.m_AIBehavior, targetGo, targetPosition);
                    this.m_AIBehavior.ChangeState(walkState);
                }
            }
        }
    }
コード例 #8
0
    public override void Initial()
    {
        ActorConfig config = ActorPrefabConfig.Instance.GetComponent <ActorConfig>();

        this.m_CurrentFrame = config.BuildAnimationFrame;

        if (SceneManager.Instance != null)
        {
            GameObject go = SceneManager.Instance.GetBuildingObjectFromBuildingObstacleMap(this.m_TargetInfo.BuildingPosition.Row,
                                                                                           this.m_TargetInfo.BuildingPosition.Column);
            if (go != null)
            {
                Transform anchorPosition = go.transform.FindChild(ClientStringConstants.BUILDING_ANCHOR_OBJECT_NAME);
                if (anchorPosition != null)
                {
                    this.m_AnimationController.PlayBuildAnimation(anchorPosition.position);
                }
                else
                {
                    this.m_AnimationController.PlayBuildAnimation(PositionConvertor.GetWorldPositionFromActorTileIndex(this.m_TargetInfo.ActorPosition));
                }
            }
        }
        else
        {
            BuildingBasePropertyBehavior property = this.m_TargetInfo as BuildingBasePropertyBehavior;
            if (property != null)
            {
                this.m_AnimationController.PlayBuildAnimation(property.AnchorTransform.position);
            }
            else
            {
                this.m_AnimationController.PlayBuildAnimation(PositionConvertor.GetWorldPositionFromActorTileIndex(this.m_TargetInfo.ActorPosition));
            }
        }
    }
コード例 #9
0
ファイル: AttackBehavior.cs プロジェクト: KangLLL/century_war
    public virtual void Fire(GameObject target, Vector2 targetPosition)
    {
        AudioController.Play(this.m_AttackConfig.AttackSound);

        GameObject           attackObject = GameObject.Instantiate(this.m_AttackConfig.AttackObjectPrefab) as GameObject;
        AttackObjectBehavior behavior     = null;

        if (this.AttackType == AttackType.Single)
        {
            behavior = attackObject.AddComponent <AttackObjectBehavior>();
        }
        else
        {
            behavior = attackObject.AddComponent <GroupAttackObjectBehavior>();
        }

        BuildingBasePropertyBehavior property = this.GetComponent <BuildingBasePropertyBehavior>();
        Vector2 deltaPosition = property == null ? targetPosition - (Vector2)transform.position :
                                targetPosition - (Vector2)property.AnchorTransform.position;
        CharacterDirection direction = DirectionHelper.GetDirectionFormVector(deltaPosition);

        Vector2 offset = Vector2.zero;

        switch (direction)
        {
        case CharacterDirection.Up:
        {
            offset = this.m_AttackConfig.AttackUpOffset;
        }
        break;

        case CharacterDirection.Down:
        {
            offset = this.m_AttackConfig.AttackDownOffset;
        }
        break;

        case CharacterDirection.Left:
        {
            offset = this.m_AttackConfig.AttackLeftOffset;
        }
        break;

        case CharacterDirection.Right:
        {
            offset = this.m_AttackConfig.AttackRightOffset;
        }
        break;

        case CharacterDirection.LeftUp:
        {
            offset = this.m_AttackConfig.AttackLeftUpOffset;
        }
        break;

        case CharacterDirection.LeftDown:
        {
            offset = this.m_AttackConfig.AttackLeftDownOffset;
        }
        break;

        case CharacterDirection.RightUp:
        {
            offset = this.m_AttackConfig.AttackRightUpOffset;
        }
        break;

        case CharacterDirection.RightDown:
        {
            offset = this.m_AttackConfig.AttackRightDownOffset;
        }
        break;
        }

        Vector2 firePosition = property == null ? (Vector2)this.transform.position :
                               (Vector2)property.AnchorTransform.position;

        attackObject.transform.position = new Vector3((firePosition + offset).x, (firePosition + offset).y, 0);
        behavior.SourceObject           = gameObject;
        behavior.SetDestinationObject(target, targetPosition, firePosition);
        if (behavior is GroupAttackObjectBehavior)
        {
            ((GroupAttackObjectBehavior)behavior).DamageScope = this.m_DamageScope;
        }

        behavior.Velocity       = this.m_BulletFlySpeed;
        behavior.Damage         = this.AttackValue;
        behavior.AttackCategory = this.m_AttackCategory;
        behavior.PushTicks      = this.m_PushTicks;
        behavior.PushVelocity   = this.m_PushVelocity;

        if (this.BulletParent != null)
        {
            attackObject.transform.parent = this.BulletParent;
        }

        for (int i = 0; i < this.m_AttackConfig.FireEffectPrefabs.Count; i++)
        {
            GameObject prefab = this.m_AttackConfig.FireEffectPrefabs[i];
            offset = this.m_AttackConfig.FireEffectOffsets[i].GetOffset(direction);
            GameObject fireEffect = GameObject.Instantiate(prefab) as GameObject;
            fireEffect.transform.position = property == null ? this.transform.position + new Vector3(offset.x, offset.y, 0) :
                                            property.AnchorTransform.position + new Vector3(offset.x, offset.y, 0);
            fireEffect.transform.parent = BattleObjectCache.Instance.EffectObjectParent.transform;
        }
    }
コード例 #10
0
    public override void AICalculate()
    {
        if (this.m_Targets == null)
        {
            if (this.m_IsFindInstantly || this.m_AIBehavior.CanTakeResponse)
            {
                this.m_TargetsObjects = new List <GameObject>();
                this.m_Targets        = this.CharacterAI.BattleSceneHelper.GetBuildingsTransformOfCategory(this.CharacterAI.FavoriteCategory);
                if (this.m_Targets.Count == 0)
                {
                    this.m_Targets = this.CharacterAI.BattleSceneHelper.GetBuildingsTransformOfCategory(BuildingCategory.Any);
                }

                this.m_SearchIndex = 0;

                this.m_Targets.Sort((x, y) => {
                    float distanceX = Vector2.SqrMagnitude((Vector2)(x.position - this.m_AIBehavior.transform.position));
                    float distanceY = Vector2.SqrMagnitude((Vector2)(y.position - this.m_AIBehavior.transform.position));
                    return(distanceX.CompareTo(distanceY));
                }
                                    );

                foreach (Transform item in this.m_Targets)
                {
                    this.m_TargetsObjects.Add(item.parent.gameObject);
                }

                Debug.Log("Total count:" + this.m_Targets.Count);
            }
        }
        else if (this.m_SearchIndex == this.m_Targets.Count)
        {
            this.SetNoWallBuildingToTarget();
        }
        else
        {
            GameObject go = this.m_TargetsObjects[this.m_SearchIndex];
            while (this.m_SearchIndex < this.m_Targets.Count && go == null)
            {
                this.m_SearchIndex++;
                if (this.m_SearchIndex < this.m_Targets.Count)
                {
                    go = this.m_TargetsObjects[this.m_SearchIndex];
                }
            }
            if (this.m_SearchIndex == this.m_Targets.Count)
            {
                this.SetNoWallBuildingToTarget();
            }
            else
            {
                GameObject target = this.m_TargetsObjects[this.m_SearchIndex++];


                if (target != null)
                {
                    BuildingBasePropertyBehavior property = target.GetComponent <BuildingBasePropertyBehavior>();
                    if (property != null)
                    {
                        TilePosition destination = property.ActorPosition + property.ActorObstacleList[0];
                        IgnoreTargetAndAttackScopeWeightStrategy findPathStrategy = new IgnoreTargetAndAttackScopeWeightStrategy(
                            this.CharacterAI.BattleMapData, destination.Row, destination.Column, this.CharacterAI.AttackBehavior.AttackScope);
                        //KodoPathFindStrage findPathStrategy = new KodoPathFindStrage(
                        //	this.CharacterAI.BattleMapData, destination.Row, destination.Column);
                        List <TilePosition> aStarPath;
                        List <TilePosition> linePath = AStarPathFinder.CalculatePathTile(findPathStrategy, this.CharacterAI.BattleMapData.ActorObstacleArray,
                                                                                         this.m_CurrentPosition, destination, out aStarPath);

                        TilePosition endPoint       = linePath[linePath.Count - 1];
                        GameObject   targetBuilding = this.CharacterAI.BattleMapData.GetBulidingObjectFromActorObstacleMap(endPoint.Row, endPoint.Column);

                        if (targetBuilding != null)
                        {
                            property = targetBuilding.GetComponent <BuildingPropertyBehavior>();
                            if (property != null && ((BuildingPropertyBehavior)property).BuildingType == BuildingType.Wall)
                            {
                                if (BattleEffectConfig.Instance.TargetEffectPrefab != null && this.CharacterAI.IsShowTarget)
                                {
                                    GameObject targetEffect = GameObject.Instantiate(BattleEffectConfig.Instance.TargetEffectPrefab) as GameObject;
                                    Vector3    offset       = targetEffect.transform.position;

                                    Vector3 targetEffectPosition = property.AnchorTransform.position;
                                    targetEffect.transform.position = targetEffectPosition + offset;
                                    targetEffect.transform.parent   = BattleObjectCache.Instance.EffectObjectParent.transform;
                                }

                                BombermanWalkState walkState = new BombermanWalkState(this.CharacterAI.BattleMapData, endPoint, this.m_AIBehavior, targetBuilding);
                                walkState.SetPath(linePath);
                                this.m_AIBehavior.ChangeState(walkState);
                            }
                        }
                    }
                }
            }
        }
    }
コード例 #11
0
 public override void Start()
 {
     this.m_NotifyRadiusSqr = this.m_NotifyRadius * this.m_NotifyRadius;
     this.m_BaseProperty    = this.GetComponent <BuildingBasePropertyBehavior>();
     base.Start();
 }