コード例 #1
0
 public override void AICalculate()
 {
     if (this.m_Target == null)
     {
         BombermanIdleState idleState = new BombermanIdleState(this.m_AIBehavior, false);
         this.m_AIBehavior.ChangeState(idleState);
     }
     else
     {
         float distanceSqr = Vector2.SqrMagnitude((Vector2)PositionConvertor.GetWorldPositionFromActorTileIndex
                                                      (this.m_TargetPosition) - (Vector2)this.m_AIBehavior.transform.position);
         if (distanceSqr <= this.CharacterAI.AttackBehavior.AttackScopeSqr)
         {
             this.m_HPBehavior.Bomb();
             List <GameObject> relatedBuildings = new List <GameObject>();
             if (this.CharacterAI.AttackBehavior.DamageScope > 0)
             {
                 relatedBuildings = BattleSceneHelper.Instance.GetNearByBuilding(this.m_AIBehavior.transform.position, this.CharacterAI.AttackBehavior.DamageScope);
             }
             else
             {
                 relatedBuildings.Add(this.m_Target);
             }
             foreach (GameObject building in relatedBuildings)
             {
                 BuildingHPBehavior targetHP = building.GetComponent <BuildingHPBehavior>();
                 targetHP.DecreaseHP(this.CharacterAI.AttackBehavior.AttackValue, this.CharacterAI.AttackBehavior.AttackCategory);
             }
         }
         else
         {
             base.AICalculate();
         }
     }
 }
コード例 #2
0
    private void Bomb(GameObject target)
    {
        BuildingHPBehavior targetHP = target.GetComponent <BuildingHPBehavior>();

        if (targetHP != null)
        {
            targetHP.DecreaseHP(this.CharacterAI.AttackBehavior.AttackValue, this.CharacterAI.AttackBehavior.AttackCategory);
        }
        KodoHPBehavior hp = this.m_AIBehavior.GetComponent <KodoHPBehavior>();

        hp.Bomb();
    }
コード例 #3
0
    protected override void Effect()
    {
        List <GameObject> removeBuilding = new List <GameObject>();

        foreach (GameObject building in this.m_AffectBuildings)
        {
            if (building == null)
            {
                removeBuilding.Add(building);
            }
            else
            {
                BuildingHPBehavior hp = building.GetComponent <BuildingHPBehavior>();
                hp.DecreaseHP(this.Damage, this.AttackCategory);
            }
        }

        foreach (GameObject building in removeBuilding)
        {
            this.m_AffectBuildings.Remove(building);
        }
    }
コード例 #4
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);
                }
            }
        }
    }
コード例 #5
0
ファイル: KodoWalkState.cs プロジェクト: KangLLL/century_war
	public override void AICalculate ()
	{
		if(this.m_Target == null)
		{
			KodoIdleState idleState = new KodoIdleState(this.m_AIBehavior, false);
			this.m_AIBehavior.ChangeState(idleState);
		}
		else
		{
			float distanceSqr = Vector2.SqrMagnitude((Vector2)PositionConvertor.GetWorldPositionFromActorTileIndex
				(this.m_TargetPosition) - (Vector2)this.m_AIBehavior.transform.position);
			if(distanceSqr <= this.CharacterAI.AttackBehavior.AttackScopeSqr)
			{
				this.m_HPBehavior.Bomb();
				BuildingHPBehavior targetHP = this.m_Target.transform.GetComponent<BuildingHPBehavior>();
				targetHP.DecreaseHP(this.CharacterAI.AttackBehavior.AttackValue, this.CharacterAI.AttackBehavior.AttackCategory);
			}
			else
			{
				base.AICalculate();
			}
		}
	}
コード例 #6
0
    public void ConstructBuilding(FindRivalResponseParameter response)
    {
        foreach (BattleRemovableObjectParameter removableObject in response.Objects)
        {
            this.ConstructRemovableObject(removableObject);
        }

        foreach (BattleDefenseObjectParameter defenseObject in response.DefenseObjects)
        {
            this.ConstructDefenseObject(defenseObject);
        }

        if (response.Buffs != null)
        {
            BuildingBuffSystem.Instance.ClearBuff();
            BuildingBuffSystem.Instance.InitialBuff(response.Buffs);
        }

        bool isReplay = Application.loadedLevelName == ClientStringConstants.BATTLE_REPLAY_LEVEL_NAME;
        Dictionary <BuildingType, int> NOGenerater = new Dictionary <BuildingType, int>();

        if (isReplay)
        {
            for (int i = 0; i < (int)BuildingType.Length; i++)
            {
                NOGenerater.Add((BuildingType)i, 0);
            }
        }
        Age  age          = Age.Prehistoric;
        bool isInitialAge = false;
        List <BuildingSurfaceBehavior> notInitialSurfaces = new List <BuildingSurfaceBehavior>();

        foreach (BattleBuildingParameter building in response.Buildings)
        {
            BuildingConfigData configData = ConfigInterface.Instance.BuildingConfigHelper.GetBuildingData(building.BuildingType, building.Level);
            string             prefabName = string.Format("{0}{1}{2}", ClientStringConstants.BATTLE_SCENE_RESOURCE_PREFAB_PREFIX_NAME,
                                                          ClientStringConstants.BUILDING_OBJECT_PREFAB_PREFIX_NAME, configData.BuildingPrefabName);

            GameObject buildingPrefab = Resources.Load(prefabName) as GameObject;
            GameObject buildingObject = GameObject.Instantiate(buildingPrefab) as GameObject;

            buildingObject.transform.position = PositionConvertor.GetWorldPositionFromBuildingTileIndex
                                                    (new TilePosition(building.PositionColumn, building.PositionRow));
            buildingObject.transform.parent = this.m_ParentNode;

            BuildingPropertyBehavior property = buildingObject.GetComponent <BuildingPropertyBehavior>();
            property.BuildingType = building.BuildingType;

            if (building.BuildingType == BuildingType.CityHall)
            {
                this.m_CurrentRivalCityHallLevel = building.Level;
                age          = CommonUtilities.CommonUtilities.GetAgeFromCityHallLevel(building.Level);
                isInitialAge = true;
            }

            if (isReplay)
            {
                property.BuildingNO = NOGenerater[building.BuildingType];
                NOGenerater[building.BuildingType]++;
            }
            else
            {
                property.BuildingNO = building.BuildingNO;
            }
            property.BuildingCategory = (BuildingCategory)configData.Category;
            property.Level            = building.Level;

            property.BuildingPosition     = new TilePosition(building.PositionColumn, building.PositionRow);
            property.BuildingObstacleList = new List <TilePosition>();
            property.ActorObstacleList    = new List <TilePosition>();
            foreach (TilePoint buildingObstacle in configData.BuildingObstacleList)
            {
                property.BuildingObstacleList.Add(buildingObstacle.ConvertToTilePosition());
            }
            foreach (TilePoint actorObstacle in configData.ActorObstacleList)
            {
                property.ActorObstacleList.Add(actorObstacle.ConvertToTilePosition());
            }

            //propert
            property.PlunderRate  = configData.PlunderRate;
            property.GoldCapacity = configData.StoreGoldCapacity;
            property.FoodCapacity = configData.StoreFoodCapacity;
            property.OilCapacity  = configData.StoreOilCapacity;

            property.Buffs = BuildingBuffSystem.Instance.GetBuffs(property.BuildingCategory);

            if (building.CurrentGold.HasValue || building.CurrentFood.HasValue || building.CurrentOil.HasValue)
            {
                property.Gold = building.CurrentGold.HasValue ? building.CurrentGold.Value : 0;
                property.Food = building.CurrentFood.HasValue ? building.CurrentFood.Value : 0;
                property.Oil  = building.CurrentOil.HasValue ? building.CurrentOil.Value : 0;

                property.Gold         = Mathf.RoundToInt(property.Gold * property.PlunderRate);
                property.Food         = Mathf.RoundToInt(property.Food * property.PlunderRate);
                property.Oil          = Mathf.RoundToInt(property.Oil * property.PlunderRate);
                property.OriginalGold = property.Gold;
                property.OriginalFood = property.Food;
                property.OriginalOil  = property.Oil;

                this.m_SceneHelper.AddProduceResourceBuilding(property);
            }
            else
            {
                if ((configData.CanStoreGold && !configData.CanProduceGold && building.Level != 0) ||
                    (configData.CanStoreFood && !configData.CanProduceFood && building.Level != 0) ||
                    (configData.CanStoreOil && !configData.CanProduceOil && building.Level != 0))
                {
                    this.m_SceneHelper.AddResourceBuilding(buildingObject,
                                                           new CapacityConfigData()
                    {
                        GoldCapacity = configData.StoreGoldCapacity,
                        FoodCapacity = configData.StoreFoodCapacity, OilCapacity = configData.StoreOilCapacity
                    });
                }
            }

            BuildingHPBehavior hp = buildingObject.GetComponent <BuildingHPBehavior>();
            hp.TotalHP       = Mathf.Max(1, configData.MaxHP + property.BuffHPEffect);
            hp.SceneHelper   = this.m_SceneHelper;
            hp.ArmorCategory = configData.ArmorCategory;

            if (building.BuilderLevel.HasValue)
            {
                BattleObstacleUpgradingInfo info = new BattleObstacleUpgradingInfo()
                {
                    AttachedBuilderLevel = building.BuilderLevel.Value, ObstacleProperty = property
                };
                this.m_SceneHelper.AddUpgradingObstacle(info);
            }
            if (building.IsUpgrading)
            {
                this.ConstructFacility(buildingObject, property);
            }

            BuildingSurfaceBehavior surface = buildingObject.GetComponent <BuildingSurfaceBehavior>();
            if (surface != null)
            {
                if (isInitialAge)
                {
                    surface.SetSurface(age, building.BuildingType);
                }
                else
                {
                    notInitialSurfaces.Add(surface);
                }
            }

            BuildingAI buildingAI = buildingObject.GetComponent <BuildingAI>();
            if (configData.CanAttack && !building.IsUpgrading)
            {
                buildingAI.enabled = false;
                AttackBehavior attackBehavior = null;
                if (configData.ApMinScope > 0)
                {
                    attackBehavior = buildingObject.AddComponent <RingAttackBehavior>();
                    ((RingAttackBehavior)attackBehavior).BlindScope = configData.ApMinScope;
                }
                else
                {
                    attackBehavior = buildingObject.AddComponent <AttackBehavior>();
                }
                int cd = Mathf.FloorToInt(configData.AttackCD * ClientConfigConstants.Instance.TicksPerSecond);
                attackBehavior.AttackCD       = Mathf.Max(1, cd - property.BuffAttackSpeedEffect);
                attackBehavior.AttackScope    = configData.ApMaxScope;
                attackBehavior.AttackValue    = Mathf.Max(1, configData.AttackValue + property.BuffAttackValueEffect);
                attackBehavior.BulletFlySpeed = configData.AttackMiddleSpeed;
                attackBehavior.AttackType     = (AttackType)configData.AttackType;
                attackBehavior.AttackCategory = configData.AttackCategory;
                attackBehavior.TargetType     = (TargetType)configData.TargetType;
                attackBehavior.DamageScope    = configData.DamageScope;
                attackBehavior.PushTicks      = configData.DamagePushTicks;
                attackBehavior.PushVelocity   = configData.DamagePushVelocity;
                attackBehavior.BulletParent   = this.m_BulletParent;

                buildingAI.AttackBehavior = attackBehavior;
                BuildingIdleState idleState = new BuildingIdleState(buildingAI, true);
                buildingAI.ChangeState(idleState);
                buildingAI.SceneHelper = BattleSceneHelper.Instance;
            }
            else
            {
                buildingAI.DetachSelf();
            }

            this.m_SceneHelper.ConstructBuilding(buildingObject);
        }

        foreach (BuildingSurfaceBehavior surface in notInitialSurfaces)
        {
            surface.SetSurface(age, surface.GetComponent <BuildingPropertyBehavior>().BuildingType);
        }

        this.m_SceneHelper.DistributeResource(response.TotalGold, response.TotalFood, response.TotalOil);


        foreach (BattleAchievementBuildingParameter achievementBuilding in response.AchievementBuildings)
        {
            this.ConstructAchievementBuilding(achievementBuilding, age);
        }
    }