public override void PostLoad() { if (this.graphicData != null) { LongEventHandler.ExecuteWhenFinished(delegate { if (this.graphicData.shaderType == ShaderType.None) { this.graphicData.shaderType = ShaderType.Cutout; } this.graphic = this.graphicData.Graphic; }); } if (this.verbs != null && this.verbs.Count == 1) { this.verbs[0].label = this.label; } base.PostLoad(); if (this.category == ThingCategory.Building && this.building == null) { this.building = new BuildingProperties(); } if (this.building != null) { this.building.PostLoadSpecial(this); } if (this.plant != null) { this.plant.PostLoadSpecial(this); } }
public BuildingEntity(MarsWorld world, BuildingProperties properties) : base(world) { this.Type = EntityType.Building; this.properties = properties; this.healthBar = new HealthBar(properties.HealthBarSize); this.size = new Point(properties.ScreenRectangle.Width, properties.ScreenRectangle.Height); this.Health = GetMaxHealth(); // initialize animations initAnimations(); // initialize sounds initSounds(); // set our animation to idle by default SetAnimation("Idle"); initBorders(); // set our grid bounds to the property's grid bounds updateGridBounds(properties.GridBounds); // set the size of our drag placement rectangle lastDragPlacement.Width = properties.GridBounds.Width; lastDragPlacement.Height = properties.GridBounds.Height; }
/// <summary> /// Hit unit target /// </summary> private void hit() { if (hasNewTarget) { //if there is a new target, get all needed variables for this target tragetProp = target.GetComponent <UnitProperties> (); tragetBuildingProp = target.GetComponent <BuildingProperties> (); fighterProp = transform.GetComponent <UnitProperties> (); hasNewTarget = false; nextActionTime = Time.time + fighterProp.actionSpeed; } if (target != null) { //Hit every X time, handle building and units if (Time.time >= nextActionTime) { if (tragetProp != null) { tragetProp.life -= findDamage(target); isTargetDead = tragetProp.life <= 0; } else if (tragetBuildingProp != null) { tragetBuildingProp.life -= fighterProp.buildingDamage; isTargetDead = tragetBuildingProp.life <= 0; } if (isTargetDead) { target = null; } nextActionTime = Time.time + fighterProp.actionSpeed; } } }
protected override bool SetFromProperties() { BuildingProperties buildingProperties = BuildingManager.instance.m_properties; NetProperties netProperties = NetManager.instance.m_properties; switch (Name) { case TextureName.UpwardRoadDiffuse: return(SetTexture(netProperties.m_upwardDiffuse)); case TextureName.DownwardRoadDiffuse: return(SetTexture(netProperties.m_downwardDiffuse)); case TextureName.BuildingFloorDiffuse: return(SetTexture(buildingProperties.m_floorDiffuse)); case TextureName.BuildingBaseDiffuse: return(SetTexture(buildingProperties.m_baseDiffuse)); case TextureName.BuildingBaseNormal: return(SetTexture(buildingProperties.m_baseNormal)); case TextureName.BuildingBurntDiffuse: return(SetTexture(buildingProperties.m_burnedDiffuse)); case TextureName.BuildingAbandonedDiffuse: return(SetTexture(buildingProperties.m_abandonedDiffuse)); case TextureName.LightColorPalette: return(SetTexture(buildingProperties.m_lightColorPalette)); default: return(false); } }
internal MaterialState(BuildingType buildingType) { this.BuildingType = buildingType; this.BuildingId = (int)buildingType; this.materialData = player.materials.materials[BuildingId]; this.properties = tracker.buildingProperties.properties[BuildingId]; }
public void Fire() { RaycastHit hit; BuildingProperties bp = GetComponentInParent <BuildingProperties>(); Debug.DrawRay(turretGunRay.position, gunPivot.TransformDirection(Vector3.left) * bp.range, Color.magenta); if (rateOfFire > bp.fireSpeed) { rateOfFire = 0; if (Physics.Raycast(turretGunRay.position, gunPivot.TransformDirection(Vector3.left), out hit, bp.range, layer)) //Create a ray from the gun in the direction it is facing. { if (hit.transform.tag == "Enemy" && target) //If it hit's an enemy { var enemyProperties = hit.transform.GetComponent <EnemyProperties>(); enemyProperties.health -= bp.damage; //Damage the enemy if (enemyProperties.health <= 0) //If enemy is dead { target.tag = "Untagged"; //Set target to null to find a new target. target = null; } } } } }
/// <summary> /// Shows the cost of selection. /// </summary> public void showCost() { int f, w, i, lvl; UnitProperties properties; BuildingProperties factoryProperties = factory.GetComponent <BuildingProperties> (); lvl = factoryProperties.level; if (unit != null) { properties = unit.GetComponent <UnitProperties> (); f = costReduced(properties.foodCost, lvl); w = costReduced(properties.woodCost, lvl); i = costReduced(properties.ironCost, lvl); } else { f = (lvl + 1) * factoryProperties.foodCost; w = (lvl + 1) * factoryProperties.woodCost; i = (lvl + 1) * factoryProperties.ironCost; } textFood.text = f.ToString(); textWood.text = w.ToString(); textIron.text = i.ToString(); toShow.SetActive(true); }
/// <summary> /// Build the specified unity. /// </summary> /// <param name="toBuild">The unit to be built</param> public void build(GameObject toBuild) { UnitProperties properties = toBuild.GetComponent <UnitProperties> (); BuildingProperties factoryProperties = buildFactory.GetComponent <BuildingProperties> (); if (properties != null && factoryProperties != null) { //calculate reduced cost according to factory level int lvl = factoryProperties.level; int f = costReduced(properties.foodCost, lvl); int w = costReduced(properties.woodCost, lvl); int i = costReduced(properties.ironCost, lvl); //check if there are enough resources if (buildSuccess(f, w, i, properties.unitCost)) { toBuild.SetActive(true); GameObject newUnit = Instantiate(toBuild, GameObject.Find("PlayerUnits").transform) as GameObject; newUnit.transform.position = new Vector3(buildFactory.transform.position.x - 5, 1.4f, buildFactory.transform.position.z); newUnit.transform.name = toBuild.name; Camera.main.transform.position = new Vector3(newUnit.transform.position.x, Camera.main.transform.position.y, newUnit.transform.position.z - Camera.main.transform.position.y); } //else print error message else { createPopUp(toBuild.name, f, w, i, properties.unitCost); } } }
public static void Postfix(WorkGiver_Scanner __instance, ref float __result, Pawn pawn, TargetInfo t) { if (!(__instance is WorkGiver_Miner) || !t.HasThing) { return; } BuildingProperties building = t.Thing.def.building; if (building == null) { return; } float p = Priority(building.mineableScatterCommonality, building.mineableScatterLumpSizeRange); if (Settings.Get().continueWork) { float damage = t.Thing.MaxHitPoints - t.Thing.HitPoints; p += damage / 1000000f; } __result = p; Log.Message($"Miner priority for {t.Thing} is {__result}"); }
/// <summary> /// Destroy the specified building. /// </summary> /// <param name="toDestroy">The building to be destroyed</param> public void destroy(GameObject toDestroy) { //find building requirements BuildingProperties properties = toDestroy.GetComponent <BuildingProperties> (); if (properties != null && properties.selfDestroyable) { //change selection if needed InputController inputController = Camera.main.transform.GetComponentInChildren <InputController> (); if (gameObject == inputController.selectedGO) { inputController.selectObject(null); } //refund player for X purcent of each building level for (int i = 1; i <= properties.level; i++) { PlayerData.food += (int)(i * properties.foodCost * (percentageBackWhenDestroy / 100f)); PlayerData.wood += (int)(i * properties.woodCost * (percentageBackWhenDestroy / 100f)); PlayerData.iron += (int)(i * properties.ironCost * (percentageBackWhenDestroy / 100f)); } PlayerData.updateResourceView(); //destroy GO properties.level = 1; toDestroy.SetActive(false); Camera.main.transform.GetComponentInChildren <InputController> ().selectObject(null); } }
/// <summary> /// Build the specified building. /// </summary> /// <param name="toBuild">The building to build</param> public void build(GameObject toBuild) { BuildingProperties properties = toBuild.GetComponent <BuildingProperties> (); if (properties != null) { //check if there are enough resources if (!toBuild.gameObject.activeSelf) { if (buildSuccess(properties.foodCost, properties.woodCost, properties.ironCost)) { toBuild.SetActive(true); } //else print error message else { createPopUp("build", toBuild.name, properties.foodCost, properties.woodCost, properties.ironCost); } } //Focus on it if it already exists if (toBuild.gameObject.activeSelf) { Camera.main.transform.position = new Vector3(toBuild.transform.position.x, Camera.main.transform.position.y, toBuild.transform.position.z - Camera.main.transform.position.y); Camera.main.transform.GetComponentInChildren <InputController> ().selectObject(toBuild); } } }
private int platformID = -1; // Use -1 when using Editor controls (WebGL builds,etc) and 0 when using mobile controls (Android, iOS). void Update() { if (Input.GetMouseButtonDown(0)) { // Check if an UI element was clicked. if (EventSystem.current.IsPointerOverGameObject(platformID)) { Debug.Log("Elemento de interfaz gráfica pulsado"); return; } Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); Debug.DrawRay(ray.origin, ray.direction * 10, Color.red); RaycastHit rayHit; if (Physics.Raycast(ray, out rayHit, maxRayDistance, clickablesLayer)) { //Debug.Log("Se ha interceptado una capa válida"); // Update actual selected building. building = rayHit.collider.transform.root.GetComponent <BuildingProperties>(); } else { //Debug.Log("No se ha interceptado una capa válida"); building = null; } } // Update mainPageButton properties based on selected building. UpdateMainPageButton(); }
public bool HasProperty(BuildingProperties prop) { if (buildingProperties.Contains(prop)) { return(true); } return(false); }
/// <summary> /// Makes the unit move target, if there's no target, give one /// </summary> private void moveToTarget() { if (hasDestination) { transform.LookAt(destination); transform.position += transform.forward * Time.smoothDeltaTime * speed; //Arrive on target if (targetGO != null) { if (targetGO.tag.Equals("FriendlyUnit")) { if ((transform.position - destination).magnitude <= 0.5f) { actionOnArrive(); } } else if (targetGO.tag.Equals("FriendlyBuilding")) { if ((transform.position - destination).magnitude <= 1.0f) { actionOnArrive(); } } } } else { targetList = GameObject.FindGameObjectsWithTag("FriendlyUnit"); if (targetList.Length > maximumNumberPlayerUnitsToAttackPlayerBase) { targetGO = targetList [Random.Range(0, targetList.Length)]; } else { targetGO = baseBuilding; } tragetProp = targetGO.GetComponent <UnitProperties> (); tragetBuildingProp = targetGO.GetComponent <BuildingProperties> (); hasDestination = true; } if (targetGO != null) { if (targetGO.tag.Equals("FriendlyBuilding")) { destination = targetGO.transform.position + new Vector3(4, 0, 0); } else if ((transform.position - targetGO.transform.position + new Vector3(1, 0, 0)).magnitude > 1f) { destination = targetGO.transform.position + new Vector3(1, 0, 0); } } else { hasDestination = false; } }
public InventoryPlacard(Building type, Vector2 position, Vector2 textOffset, BuildingProperties properties, int members) { this.type = type; this.position = position; this.textOffset = textOffset; this.text = properties.Description; this.members = members; this.color = properties.InventoryColor; }
private static float TurretWarmup(StatRequest req, BuildingProperties buildingProps) { if (req.Thing != null && req.Thing.IsUpgraded(out var upgradableComp)) { return(buildingProps.turretBurstWarmupTime * upgradableComp.Props.turretBurstWarmupTimeFactor); } return(buildingProps.turretBurstWarmupTime); }
void Start() { //Initialise variables tragetProp = null; tragetBuildingProp = null; fighterProp = null; hasNewTarget = false; isTargetDead = false; }
void Start() { properties = GetComponent <BuildingProperties> (); attackZone = gameObject.AddComponent <SphereCollider> (); attackZone.isTrigger = true; attackZone.radius = properties.radius; cooldown = 0; }
private void GameManager_DayTick() { ProductionBuilding building; //If the tile is owned and has a building, have the player pay rent. If they can't afford rent disable the building for today. if (purchased && (building = GetComponent <ProductionBuilding>())) { building.powered = Player.Withdraw(properties.tileRentCost, transform.position, false); } }
private static float TurretCooldown(StatRequest req, BuildingProperties buildingProps) { if (req.Thing is Building_TurretGun gunTurret) { return(NonPublicMethods.Building_TurretGun_BurstCooldownTime(gunTurret)); } return(buildingProps.turretBurstCooldownTime > 0 ? buildingProps.turretBurstCooldownTime : buildingProps.turretGunDef.GetStatValueAbstract(StatDefOf.RangedWeapon_Cooldown)); }
private void rescaleSprite() { BuildingProperties properties = this.gameObject.GetComponent <BuildingProperties>(); float mSpriteWidth = mRenderer.sprite.bounds.size.x; float mSpriteHeight = mRenderer.sprite.bounds.size.y; float scaleH = (properties.baseCellsWidth * GridOperations.sharedInstance.cellWidth) / mSpriteWidth; float scaleV = ((properties.baseCellsHeight + properties.noOfCellsHigh) * GridOperations.sharedInstance.cellHeight) / mSpriteHeight; transform.localScale = new Vector3(scaleH, scaleV, 1.0f); }
private static void CanUsebedEverPostfix(ref bool __result, [NotNull] Pawn p, ThingDef bedDef) { if (!__result && p.GetIntelligence() == Intelligence.Humanlike) { __result = bedDef?.building?.bed_humanlike == true; } else if (__result && p.GetIntelligence() < Intelligence.ToolUser) { BuildingProperties building = bedDef?.building; __result = building != null && p.BodySize <= (double)building.bed_maxBodySize; } }
/// <summary> /// Attempts to purchase a building. If the conditions are met, will place building. /// </summary> internal bool PurchaseBuilding(BuildingProperties properties) { if (building == null && Player.Withdraw(properties.cost, transform.position)) { PlaceBuilding(properties); return(true); } else { return(false); } }
private void OnCollisionStay(Collision collision) { if ((collision.gameObject.tag == "Wall") || (collision.gameObject.tag == "Satellite")) //If the enemy is hitting a building { BuildingProperties bp = collision.gameObject.GetComponent <BuildingProperties>(); if (attackSpeed > ep.attackSpeed) //And the enemy has ran through the attack cycle { robAnim.attackAnimPlay(); //Play the attack animation attackSpeed = 0; //Reset the attack cycle bp.health -= ep.damage; //Remove health from the hit building equal to the enemy's damage value. } } }
// Update is called once per frame void Update() //Function checks for whichever tower is clicked and displays the relevant data on the UI buttons for upgrading and selling. { if (bm.clickedTower != null) { bp = bm.clickedTower.GetComponent <BuildingProperties>(); } if (bp != null) { health.text = "HP: " + bp.health.ToString(); upgradeCost.text = "Upgrade Cost: " + bp.upgradeCost.ToString(); sellPrice.text = "Sell: " + bp.sellPrice.ToString(); } }
// Use this for initialization void Start() { Vector3[] pts = initShape2(); ShapeObject so = ShapeObject.CreateExtrusion(pts, 30); Grammar g1 = new Grammar(); g1.inputs.shapes.Add(so); g1.AddRule(new Rules.Scale3D("A", "A", new Vector3(1, 1, 1))); Properties buildingA = new BuildingProperties(); buildingA.AddGrammar(g1); }
/// <summary> /// Explictly places a building on this tile. /// </summary> public void PlaceBuilding(BuildingProperties properties) { building = properties; buildPrimary.sprite = properties.spritePrimary; buildSecondary.sprite = properties.spriteSecondary; buildExtra.sprite = properties.spriteExtra; buildBackground.sprite = properties.spriteBackground; if (properties.GetType() == typeof(ProductionProperties)) { ProductionBuilding production = gameObject.AddComponent <ProductionBuilding>(); production.InitializeBuilding((ProductionProperties)properties); } }
public bool PurchaseBuilding(GameObject buildingObject) { BuildingProperties bp = buildingObject.GetComponent <BuildingProperties>(); if (bp != null && bp.GoldCost <= CurrentGold) { CurrentGold -= bp.GoldCost; return(true); } else { return(false); } }
/// <summary> /// Build the unit given in class attribute /// </summary> public void build() { UnitProperties properties = toBuild.GetComponent <UnitProperties> (); BuildingProperties factoryProperties = buildFactory.GetComponent <BuildingProperties> (); toBuild.SetActive(true); GameObject newUnit = Instantiate(toBuild, GameObject.Find("EnemyUnits").transform) as GameObject; newUnit.transform.position = new Vector3(buildFactory.transform.position.x - 5, 1.4f, buildFactory.transform.position.z); newUnit.transform.name = toBuild.name; EnemyUnitController euc = newUnit.AddComponent <EnemyUnitController> (); euc.baseBuilding = playerBaseBuilding; }
/// <summary> /// Sells the building on the tile. /// </summary> internal void Sell() { if (building != null) { Player.Deposit(building.value, transform.position); Destroy(GetComponent <ProductionBuilding>()); building = null; //Stop particle systems to prevent them from lingering. var emission = goldParticles.emission; emission.rateOverTime = 0; smokeParticles.Stop(); } }