/// <summary> /// 获取自身的战斗目标的阵营 /// </summary> /// <returns></returns> public OwnerType GetTargetOwner() { // 治疗者(获取自身 if (EntityTypeUtil.IsCurer(model)) { return(GetOwner()); } // 其他(获取对方 else { return(GetPeerOwner()); } }
/// <summary> /// 战斗开始 /// </summary> public void StartBattle() { if (IsBattleStarted) { return; } IsBattleStarted = true; IsoMap.Instance.HideGuardAreaMap(); //计算每个建筑的百分比 var allEntities = IsoMap.Instance.GetAllEntitiesByOwner(OwnerType.Defender); foreach (var tileEntity in allEntities) { if (EntityTypeUtil.IsAnyNonWallBuilding(tileEntity.entityType)) { ++defenderBuildingCount; } } totalDefenderBuildingCount = defenderBuildingCount; //计算士兵数量 foreach (var armyVo in DataCenter.Instance.Attacker.armies) { attackerArmyCount += armyVo.amount; var model = DataCenter.Instance.FindEntityModelById(armyVo.cid); if (EntityTypeUtil.IsCurer(model)) { attackerCurerCount += armyVo.amount; } } //加上援军的士兵数量 foreach (var donatedArmy in DataCenter.Instance.Attacker.donatedArmies) { attackerArmyCount += donatedArmy.amount; var model = DataCenter.Instance.FindEntityModelById(donatedArmy.cid); if (EntityTypeUtil.IsCurer(model)) { attackerCurerCount += donatedArmy.amount; } } //备份进攻方和防守方的数据,提交服务器时使用 attackerData = ProtoBuf.Serializer.DeepClone(DataCenter.Instance.Attacker); defenderData = ProtoBuf.Serializer.DeepClone(DataCenter.Instance.Defender); }
/// <summary> /// 计算目标的伤害值(伤害公式) /// </summary> /// <param name="targeterModel"></param> /// <param name="attackerModel"></param> /// <param name="attacker">技能道具等情况下 attacker 为 null </param> /// <param name="factor">伤害修正系数</param> /// <returns></returns> private static float CalcDamageValue(EntityModel targeterModel, EntityModel attackerModel, TileEntity attacker = null, float factor = 1.0f) { float damage = 0.0f; if (EntityTypeUtil.IsCurer(attackerModel)) { // 回血为负 damage = -factor * attackerModel.cure; } else { // REMARK:伤害公式可以调整 damage = attackerModel.damage - targeterModel.defense; if (attackerModel.additionDamageSubType != Constants.EMPTY && attackerModel.additionDamageSubType == targeterModel.subType) { damage *= attackerModel.additionDamageRatio; } // 技能伤害的时候 attacker 不存在 if (attacker != null) { // [攻击提升] buffer 的情况下乘以伤害倍率 GameBufferComponent attackerBufferMgr = attacker.GetComponent <GameBufferComponent>(); if (attackerBufferMgr != null) { var buffer = attackerBufferMgr.GetBuffer(Constants.BUFF_TYPE_ATTACKUP); if (buffer != null) { damage *= buffer.buffDamage; } } } damage = Mathf.Max(damage * factor, 0); } // 处理伤害 return(damage); }
private bool MyTargeterFilter(TileEntity tar) { // 过滤掉治疗兵 return(EntityTypeUtil.IsCurer(tar.model)); }
public static TileEntity Create(OwnerType owner, EntityModel model, bool isFriendly = false) { var entityObj = LoadAndCreate(model); var tileEntity = new TileEntity(); tileEntity.owner = owner; tileEntity.model = model; tileEntity.State = EntityStateType.Idle; tileEntity.aiType = (EntityAiType)model.targetType; tileEntity.entityType = model.entityType; tileEntity.Friendly = isFriendly; if (model.tileSize > 0) { tileEntity.width = tileEntity.height = model.tileSize * 2; // REMARK:建筑实际占用格子扩大2倍 } else { tileEntity.width = tileEntity.height = 1; } tileEntity.currentHp = tileEntity.maxHp = Mathf.Max(model.hp, 1); // REMARK:这里设置最大hp的最小值为1,不然对于工人等直接就是dead状态。 tileEntity.animationNamePrefix = model.nameForResource + "_"; // REMARK:建筑按照格子建造、士兵按照边行走(所以士兵位置比建筑偏移(0.5,0.5)) if (EntityTypeUtil.IsAnyActor(model.entityType)) { tileEntity.renderTileSizeOffset = new Vector2((tileEntity.width * 0.5f) - 1.0f, (tileEntity.height * 0.5f) - 1.0f); } else { tileEntity.renderTileSizeOffset = new Vector2((tileEntity.width * 0.5f) - 0.5f, (tileEntity.height * 0.5f) - 0.5f); } tileEntity.view = entityObj.GetComponent <EntityViewComponent>(); if (tileEntity.view == null) { if (EntityTypeUtil.IsAnyActor(tileEntity.entityType)) { tileEntity.view = entityObj.AddComponent <ActorView>(); } else if (EntityTypeUtil.IsAnyTower(tileEntity.entityType)) { tileEntity.view = entityObj.AddComponent <TowerView>(); } else { tileEntity.view = entityObj.AddComponent <EntityViewComponent>(); } } if (EntityTypeUtil.IsAnyBuilding(tileEntity.entityType))//[建筑类] { //1格以上建筑有地皮 if (model.tileSize > 2) { var floorBase = (GameObject)ResourceManager.Instance.LoadAndCreate(model.raceType + "/Entities/Misc/Floor4");//地皮 tileEntity.view.AddSubView(floorBase, Vector3.zero); IsoHelper.FaceToWorldCamera(floorBase.transform); IsoHelper.MoveAlongCamera(floorBase.transform, Constants.FLOOR_Z_ORDER); floorBase.transform.localScale = Vector3.one * model.tileSize / 4;//REMARK 现有素材占4x4个tilesize } if (EntityTypeUtil.IsBarracks(model)) { tileEntity.blockingRange = 3; } else { tileEntity.blockingRange = model.tileSize * 2 - 1; } tileEntity.AddComponent <ConstructBuildingComponent>(); if (model.entityType == EntityType.Tower) { tileEntity.AddComponent <TowerComponent>(); } else if (model.entityType == EntityType.Wall) { tileEntity.AddComponent <WallComponent>(); } else if (EntityTypeUtil.IsGatherResourceBuilding(model)) { tileEntity.AddComponent <GatherResourceBuildingComponent>(); } else if (EntityTypeUtil.IsStorageResoruceBuilding(model)) { tileEntity.AddComponent <ResourceStorageBuildingComponent>(); } else if (EntityTypeUtil.IsArmyShop(model)) { tileEntity.AddComponent <ProductSoldierBuildingComponent>(); } else if (EntityTypeUtil.IsSkillShop(model)) { tileEntity.AddComponent <ProductSkillBuildingComponent>(); } else if (EntityTypeUtil.IsWorkerHouse(model)) { tileEntity.AddComponent <WorkerHouseComponent>(); } else if (EntityTypeUtil.IsFederal(model)) { tileEntity.AddComponent <FederalComponent>(); } else if (EntityTypeUtil.IsResearch(model)) { tileEntity.AddComponent <ResearchBuildingComponent>(); } } else if (EntityTypeUtil.IsAnyActor(model.entityType)) //[角色类] { // 战斗模式 家园模式 通用组件 tileEntity.AddComponent <ActorMoveComponent>(); if (GameWorld.Instance.worldType == WorldType.Home || GameWorld.Instance.worldType == WorldType.Visit) //家园模式 或者 访问模式 { // 家园模式 // 工人(添加工人组件&添加到工人小屋中) if (EntityTypeUtil.IsWorker(model)) { tileEntity.AddComponent <WorkmanComponent>(); var houseComp = IsoMap.Instance.GetWorkerHouseComponent(); Assert.Should(houseComp != null, "worker house is not exist..."); houseComp.AddAWorkman(tileEntity); } else { tileEntity.AddComponent <ArmyComponent>(); } } else //战斗模式 { tileEntity.AddComponent <GameBufferComponent>(); // 设置士兵的监视范围(寻找目标用) REMARK:设定为4.0秒可以移动的范围 tileEntity.monitorRange = Mathf.Clamp(model.speed * 4.0f, 5.0f, 20.0f); if (EntityTypeUtil.IsBombMan(model)) { tileEntity.monitorRange = 0.0f; // 暂时不限制炸弹人 tileEntity.AddComponent <BombManComponent>(); } else if (EntityTypeUtil.IsCurer(model)) { tileEntity.AddComponent <CurerComponent>(); } else if (isFriendly) // 友军/援军 { tileEntity.AddComponent <FriendComponent>(); } else { tileEntity.AddComponent <ActorComponent>(); } // 除【友军/援军】以外添加拆墙组件(REMARK:友军/援军不可拆墙) if (!isFriendly) { tileEntity.AddComponent <ActorDestroyWallComponent>(); } } } else if (EntityTypeUtil.IsAnyTrap(model)) // [陷阱类] { tileEntity.AddComponent <TrapComponent>(); } Assert.Should((tileEntity.blockingRange == 0 || (tileEntity.blockingRange % 2) == 1), "invalid blockingRange..."); Assert.Should(tileEntity.blockingRange <= tileEntity.width - 1 && tileEntity.blockingRange <= tileEntity.height - 1, "invalid blockingRange..."); return(tileEntity); }
/// <summary> /// 有单位死亡了 /// </summary> /// <param name="entity"></param> public void OnEntityDestroy(TileEntity entity) { //如果死亡的是建筑 if (EntityTypeUtil.IsAnyNonWallBuilding(entity.entityType)) { defenderBuildingCount--; DestroyBuildingPercent = (float)(totalDefenderBuildingCount - defenderBuildingCount) / totalDefenderBuildingCount; //摧毁50% 获得一颗星 if (!hasGotHalfDestroyStar && DestroyBuildingPercent > 0.5f) { hasGotHalfDestroyStar = true; BattleStar++; } Debug.Log("摧毁:" + DestroyBuildingPercent + "%"); //摧毁基地 获得一颗星 if (EntityTypeUtil.IsCenterBuilding(entity.model)) { BattleStar++; } //摧毁100% 获得一颗星 if (defenderBuildingCount == 0) { BattleStar++; } EventDispather.DispatherEvent(GameEvents.BATTLE_PROGRESS_CHANGE); } else if (entity.GetOwner() == OwnerType.Attacker && EntityTypeUtil.IsAnyActor(entity.entityType)) { attackerArmyCount--; if (EntityTypeUtil.IsCurer(entity.model)) { attackerCurerCount--; } } else if (entity.GetOwner() == OwnerType.Defender) { if (EntityTypeUtil.IsAnyActor(entity.entityType)) { if (entity.Friendly) { var found = false; foreach (var killedDefenderDonatedArmy in killedDefenderDonatedArmies) { if (killedDefenderDonatedArmy.cid == entity.model.baseId) { killedDefenderDonatedArmy.amount++; found = true; break; } } if (!found) { killedDefenderDonatedArmies.Add(new ArmyVO() { amount = 1, cid = entity.model.baseId }); } } } else if (EntityTypeUtil.IsAnyTrap(entity.model)) { brokenTraps.Add(entity.buildingVO.sid); } } CheckBattleEnd(); }