static void Postfix(ProjectileDefense __instance, ref int __result) { try { Cell cell = World.inst.GetCellData(__instance.transform.position); if (cell != null) { CellMark mark = ElevationManager.GetCellMark(cell); if (mark != null) { __result += mark.elevationTier; } } } catch (Exception ex) { DebugExt.HandleException(ex); } }
public void Preload(KCModHelper _helper) { helper = _helper; String modpath = helper.modPath; assetBundle = KCModHelper.LoadAssetBundle(modpath + "\\AssetBundle", "cannonbundle"); if (assetBundle != null) { cannonPrefab = assetBundle.LoadAsset("assets/workspace/Cannon.prefab") as GameObject; cannonBallPrefab = assetBundle.LoadAsset("assets/workspace/CannonBall.prefab") as GameObject; if (cannonPrefab == null) { helper.Log("Cannon Prefab Could Not Be Loaded"); } if (cannonBallPrefab == null) { helper.Log("CannonBall Prefab Could Not Be Loaded"); } Projectile cannonP = cannonBallPrefab.AddComponent <Projectile>(); cannonP.attackDamage = 85f; cannonP.hitRadius = 1f; Building cannonB = cannonPrefab.AddComponent <Building>(); ProjectileDefense cannonPD = cannonPrefab.AddComponent <ProjectileDefense>(); MaxRangeDisplay cannonMRD = cannonPrefab.AddComponent <MaxRangeDisplay>(); BuildingCollider cannonCOL = cannonPrefab.transform.Find("Offset").Find("cannon").gameObject.AddComponent <BuildingCollider>(); Cannon cannon = cannonPrefab.AddComponent <Cannon>(); cannon.b = cannonB; cannon.pd = cannonPD; cannon.flag = cannonPrefab.transform.Find("Offset").Find("cannon").Find("flag").gameObject; cannon.veteranDecor = cannonPrefab.transform.Find("Offset").Find("cannon").Find("cannon_veteran"); cannon.RotateParent = cannonPrefab.transform.Find("Offset").Find("cannon").Find("cannon_top"); cannonPD.b = cannonB; cannonPD.projectilePrefab = cannonP; cannonPD.AttackTime = 10f; cannonPD.AttackRange = 5f; cannonPD.TrackingRange = 7f; cannonPD.rangeIncreasePerHeight = 3f; cannonCOL.Building = cannonB; BuildingInfo cannonInfo = new BuildingInfo(cannonPrefab, "cannon"); cannonInfo.building = cannonB; cannonInfo.customName = "Cannon"; cannonInfo.descOverride = "Cannon that goes boom boom..."; cannonInfo.workersForFullYield = 4; cannonInfo.buildAllowedWorkers = 6; cannonInfo.placementSounds = new string[] { "castleplacement" }; cannonInfo.selectionSounds = new string[] { "BuildingSelectCastleGate" }; cannonInfo.skillUsed = "Ballisteer"; cannonInfo.jobCategory = JobCategory.Ballista; cannonInfo.categoryName = "projectiletopper"; cannonInfo.ignoreRoadCoverageForPlacement = true; ResourceAmount cannonResourceAmount = default(ResourceAmount); cannonResourceAmount.Add(ResourceAmount.Make(FreeResourceType.Tree, 45)); cannonResourceAmount.Add(ResourceAmount.Make(FreeResourceType.Stone, 10)); cannonResourceAmount.Add(ResourceAmount.Make(FreeResourceType.Gold, 35)); cannonResourceAmount.Add(ResourceAmount.Make(FreeResourceType.IronOre, 10)); cannonInfo.buildingCost = cannonResourceAmount; cannonInfo.personPositions = new Transform[4]; cannonInfo.preqBuilding = "chamberofwar"; cannonInfo.tabCategory = "Castle"; Transform cannon_offset = cannonPrefab.transform.Find("Offset"); Transform[] cannon_peepo_positions = new Transform[4]; for (int i = 1; i < 5; i++) { Transform peep = cannon_offset.Find(("p" + i.ToString())); cannon_peepo_positions[i - 1] = peep; } cannonInfo.personPositions = cannon_peepo_positions; BuildingHelper.RegisterBuilding(cannonInfo); // Initalizing Harmony Patches var harmony = HarmonyInstance.Create("harmony"); harmony.PatchAll(Assembly.GetExecutingAssembly()); } else { helper.Log("Bundle Not Loaded"); } }
// Takes into account if move target is a Transport Ship. Since Transport Ship is not IProjectileHitable, this // returns the ShipBase, which is IProjectileHitable. private static System.Object GetAttackTarget(UnitSystem.Army army, ArcherGeneral archerGeneral) { if (army.locked && army.moveTarget != null) { System.Object moveTarget = army.moveTarget; Vector3 targetPos; // Refer to ProjectileDefense::GetTarget for getting target position. if (moveTarget is TroopTransportShip) { // Prevents friendly fire. if (((TroopTransportShip)moveTarget).TeamID() != 0) { ShipBase shipBase = ((TroopTransportShip)moveTarget).shipBase; moveTarget = shipBase; targetPos = shipBase.GetPos(); } else { return(null); } } else if (moveTarget is SiegeMonster) { SiegeMonster ogre = (SiegeMonster)moveTarget; if (ogre.IsInvalid()) { // Ogre died or got on a ship, stop tracking. army.moveTarget = null; return(null); } targetPos = ogre.GetPos(); } else if (moveTarget is IProjectileHitable) { if (moveTarget is UnitSystem.Army && ((UnitSystem.Army)moveTarget).IsInvalid()) { // Army died or got on a ship, stop tracking. army.moveTarget = null; return(null); } targetPos = ((IProjectileHitable)moveTarget).GetPosition(); } else { return(null); } // If moveTarget is not in range, returning null will make archer seek another target until moveTarget // is in range. This is because moveTarget will not change until it is dead, or the player clicked on a // different target. // Refer to ArcherGeneral::Update and ProjectileDefense::GetTarget for range calculation. Vector3 archerPos = army.GetPos(); float attackRange = archerGeneral.FullRange(archerGeneral.attackRange) + 1f; if (!ProjectileDefense.TestRange(targetPos, archerPos, attackRange)) { return(null); } return(moveTarget); } else { // If not on ship, don't change the behavior. return(army.moveTarget); } }