public static void deliverTo(GameObject to, bool important, ressources kind) { print("got deliver request: to=" + to + " important=" + important + " kind=" + kind); //get closest worker GameObject[] movers = GameObject.FindGameObjectsWithTag("mover"); Transform mover = harvestableRessource.GetClosestMover(movers, !important, to.transform); //stop if no worker has been found if (mover == null) { print("no mover found!"); return; } //find container with the ressource kind var results = GameObject.FindGameObjectsWithTag("dropBase"); foreach (var obj in results) { //check if res has kind, if true then order worker to deliver it and stop if (obj.GetComponent <inventory>().getAmount(kind) > 1) { var stack = new ressourceStack(obj.GetComponent <inventory>().getAmount(kind), kind); mover.GetComponent <ActionController>().deliverTo(obj, to, stack); print("handled delivery request successfully"); return; } } print("unable to handle request!"); }
/// <summary> /// Start is called on the frame when a script is enabled just before /// any of the Update methods is called the first time. /// </summary> public override void Start() { base.Start(); var patches = GameObject.FindObjectsOfType <deepRessource>(); print("starting deepDrill script, #patches: " + patches.Length); GameObject res = null; var dist = float.MaxValue; foreach (var elem in patches) { var d = Vector3.Distance(elem.gameObject.transform.position, this.gameObject.transform.position); if (d < dist) { dist = d; res = elem.gameObject; } } ingot = res.GetComponent <HPHandler>().type; if (res.GetComponent <deepRessource>().activeDrill != null) { return; } mineralPatch = res; res.GetComponent <deepRessource>().activeDrill = this.gameObject; }
public void handleDeserialization(SaveLoad.SerializationInfo info) { serializationData data = (serializationData)info; print("deserilazing HP handler..., HP=" + data.HP); this.HP = data.HP; this.initialHP = data.initialHP; this.type = data.type; }
public bool isSame(GameObject origin, GameObject target, ressources type) { if (origin == this.origin && target == this.target && type == this.type) { return(true); } return(false); }
public static void addRoute(GameObject origin, GameObject target, ressources type) { if (routeExists(origin, target)) { return; } routes.Add(new routeSolotype(origin, target, type)); Debug.Log("created new route from " + origin.name + " to" + target.name + " with kind " + type); }
public void transferSafe(inventory target, ressources item) { var amount = newContent[item]; if (amount > target.getFreeSpace()) { amount = target.getFreeSpace(); } target.newContent[item] += amount; this.newContent[item] -= amount; }
public static float getAmoumt(ressources res) { int i = 0; foreach (ressources cur in System.Enum.GetValues(typeof(ressources))) { if (res.Equals(cur)) { return(getInstance().totalRessources[i]); } i++; } return(0); }
public static bool deleteRoute(GameObject origin, GameObject target, ressources type) { Debug.Log("deleting route..."); foreach (routeSolotype route in routes) { if (route.isSame(origin, target, type)) { routes.Remove(route); Debug.Log("succesfully deleted route"); return(true); } } return(false); }
public void add(ressources type, float amount) { this.newContent[type] += amount; }
public void transfer(inventory target, ressources type, float amount) { target.newContent[type] += amount; this.newContent[type] -= amount; }
public serializationData(float HP, ressources type, float initialHP) { this.HP = HP; this.type = type; this.initialHP = initialHP; }
public void takeAmount(ressources kind, float amount) { newContent[kind] -= amount; }
public float getAmount(ressources kind) { return(newContent[kind]); }
public float getFillPercent(ressources kind) { return(this.getAmount(kind) / this.maxSize); }
public bool canTake(ressources kind, float amount) { return(newContent[kind] >= amount); }
public void setIngot(ressources ingot, GameObject patch) { print("set ingot type: " + ingot + " on " + this.name); this.ingot = ingot; this.mineralPatch = patch; }
public routeSolotype(GameObject origin, GameObject target, ressources type) { this.origin = origin; this.target = target; this.type = type; }
public ressourceStack(float amount, ressources type) { this.amount = amount; this.type = type; }