/// <summary> /// Copy from loaded item. /// shouldn't copy non-serialized fields /// </summary> /// <param name="source"> source for copying </param> public override void Copy(AbstractObject source) { base.Copy(source); GameAbstractItem itm = source as GameAbstractItem; m_workers = itm.m_workers; }
/// <summary> /// parsing excel data into current format /// </summary> /// <param name="itm">target</param> /// <param name="repItm">source</param> /// <returns> parsed item </returns> public static new AbstractObject Parse(AbstractObject itm, ExcelLoading.AbstractObject repItm) { Localization loc = Localization.GetLocalization(); ExcelLoading.ScienceItem rep = (ExcelLoading.ScienceItem)repItm; Science scs = (Science)itm; scs.m_repItem = rep; scs.m_tooltipCount = loc.m_ui.m_scienceCount; scs.m_tooltipProductivity = loc.m_ui.m_scienceProductivity; Productions.AddProduction(scs, "science"); return(GameAbstractItem.Parse(itm, repItm)); }
/// <summary> /// Numbers outputs /// </summary> void PrintTextValue() { m_txtCount.text = m_thisItem.GetCountString(); GameAbstractItem itm = m_thisItem as GameAbstractItem; if (itm != null && m_txtCount != null) { m_workers.text = itm.m_workers.ToString(); m_productText.text = m_thisItem.GetProductivityString(); if (m_thisItem.m_isItDestroyable) { m_damagedText.text = ((Items)m_thisItem).GetDamagedString(); } } }
/// <summary> /// Check + and - buttons conditions: should it be enabled or not? /// </summary> void CheckButtons() { if (m_people.WorkersNumber > 0 && m_thisItem.m_isItIterable && !_isButtonPlusEnabled) { m_plus.interactable = true; _isButtonPlusEnabled = true; } GameAbstractItem itm = m_thisItem as GameAbstractItem; if (itm != null && itm.m_workers > 0 && m_thisItem.m_isItIterable && !_isButtonMinusEnabled) { m_minus.interactable = true; _isButtonMinusEnabled = true; } }
/// <summary> /// parsing excel data into current format /// </summary> /// <param name="mat">target</param> /// <param name="rep">source</param> /// <returns> parsed item </returns> /// <returns></returns> public static new AbstractObject Parse(AbstractObject mat, ExcelLoading.AbstractObject rep) { AbstractAnimal ani = mat as AbstractAnimal; ExcelLoading.AbstractAnimal aniRep = rep as ExcelLoading.AbstractAnimal; if (ani != null && aniRep != null) { ani.m_butcheringPerPerson = GameAbstractItem.ParseDependencyCounts(aniRep.butchering_per_person); } else { Debug.Log("AbstractAnimal.Parse: critical parse error"); } return(Resource.Parse(mat, rep)); }
/// <summary> /// Enable/disable buttons /// </summary> void ChangeButtonsConditions() { if (!m_thisItem.m_isItIterable) { _isButtonPlusEnabled = false; m_plus.interactable = false; } else if (m_people != null) { if (m_people.WorkersNumber == 0 && _isButtonPlusEnabled) { m_plus.interactable = false; _isButtonPlusEnabled = false; } else if (m_people.WorkersNumber > 0 && !_isButtonPlusEnabled) { _isButtonPlusEnabled = true; m_plus.interactable = true; } } GameAbstractItem itm = m_thisItem as GameAbstractItem; if (itm != null && itm.m_workers == 0 && _isButtonMinusEnabled) { _isButtonMinusEnabled = false; m_minus.interactable = false; } if (m_thisItem.CheckUpgradeConditions() && m_thisItem.m_isItIterable) { if (!_isUpgradeButtonEnabled) { m_up.interactable = true; } _isUpgradeButtonEnabled = true; } else { if (_isUpgradeButtonEnabled) { m_up.interactable = false; } _isUpgradeButtonEnabled = false; } }
/// <summary> /// Button + click function. Set only one worker /// </summary> public void ButtonPlusClick() { GameAbstractItem itm = m_thisItem as GameAbstractItem; if (itm != null && m_people.GetWorker()) { itm.m_workers++; if (itm.m_workers == 1) { m_minus.interactable = true; _isButtonMinusEnabled = true; } m_workers.text = itm.m_workers.ToString(); } }
/// <summary> /// parsing excel data into current format /// </summary> /// <param name="itm">target</param> /// <param name="repItm">source</param> /// <returns> parsed item </returns> public static new AbstractObject Parse(AbstractObject itm, ExcelLoading.AbstractObject repItm) { ExcelLoading.MaterialItem rep = (ExcelLoading.MaterialItem)repItm; GameMaterial mat = (GameMaterial)itm; mat.m_size = rep.container; mat.m_container = rep.container_type.ParseCont(); string[] prods = rep.production_type.Split('&'); foreach (string prod in prods) { string prodTmp = prod.Trim(); mat.m_productionType.Add(prodTmp); Productions.AddProduction(mat, prodTmp); } mat.m_onWork = mat.WorkComplite; return(GameAbstractItem.Parse(mat, rep)); }
/// <summary> /// parsing excel data into current format /// </summary> /// <param name="mat">target</param> /// <param name="rep">source</param> /// <returns> parsed item </returns> /// <returns></returns> public static new AbstractObject Parse(AbstractObject mat, ExcelLoading.AbstractObject rep) { DomesticAnimal ani = mat as DomesticAnimal; ExcelLoading.DomesticAnimalItem aniRep = rep as ExcelLoading.DomesticAnimalItem; if (ani != null && aniRep != null) { ani.m_container = aniRep.storageType.ParseCont(); ani.m_producePerPerson = aniRep.produce_per_person; ani.m_foodType = GameAbstractItem.ParseDependencyCounts(aniRep.foodType); ani.m_additionalProduction = GameAbstractItem.ParseDependencyCounts(aniRep.additionalProducts); //link to domesticAnimal!!! _sAllDomesticAnimal.Add(ani); } else { Debug.Log("WildAnimal.Parse: critical parse error"); } return(AbstractAnimal.Parse(mat, rep)); }
/// <summary> /// loading data from xml files /// </summary> public void Loading() { //order is important! from parents to children, science the last one EffectTypeHolder.Load("effect_map"); MineralResource.Load("mineralResource_Map"); //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount()); Resource.Load("resource_Map"); //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount()); GameMaterial.Load("materials_Map"); //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount()); Items.Load("items_Map"); //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount()); Buildings.Load("buildings_Map"); //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount()); Army.Load("army_map"); //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount()); Process.Load("process_map"); //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount()); Science.Load("science_map"); //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount()); DomesticAnimal.Load("domesticAnimal_map"); //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount()); WildAnimal.Load("wildAnimal_map"); //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount()); LearningTip.Load("AllTips_Map"); GameAbstractItem.ParseDependency(); Population ppl = new Population { m_people = GetComponent <People>(), m_isItOpen = 1 }; AbstractObject.m_sEverything.Add(ppl); Localization.GetLocalization().FirstLoad(); Localization.GetLocalization().ChangeLanguage(Localization.GetLocalization().m_currentLanguage); AbstractObject.ClearUnparsed(); Debug.Log("loading finished"); }
/// <summary> /// Button - function. Set only one worker /// </summary> public void ButtonMinusClick() { GameAbstractItem itm = m_thisItem as GameAbstractItem; if (itm != null) { itm.m_workers--; if (itm.m_workers < 0) { itm.m_workers = 0; return; } if ((itm.m_workers == 0 || !m_thisItem.m_isItIterable) && _isButtonMinusEnabled) { m_minus.interactable = false; _isButtonMinusEnabled = false; } m_workers.text = itm.m_workers.ToString(); m_people.ReturnWorker(); } }
/// <summary> /// Check how many free workers in the colony /// </summary> public void CheckWorkersCount() { long wrks = 0; foreach (AbstractObject itm in AbstractObject.m_sEverything) { GameAbstractItem git = itm as GameAbstractItem; if (git != null && git.GetType() != typeof(Population) && git.m_workers > 0) { wrks += (long)git.m_workers; } } if (wrks + _workers != _people) { _workers += _people - (wrks + _workers); int i = AbstractObject.m_sEverything.Count - 1; while (_workers < 0 && i > -1) { GameAbstractItem itm = AbstractObject.m_sEverything[i] as GameAbstractItem; if (itm != null) { if ((long)itm.m_workers + _workers > 0) { itm.m_workers += _workers; _workers = 0; } else { _workers += (long)itm.m_workers; itm.m_workers = 0; } } i--; } } }
/// <summary> /// Upgrade button click. /// Called by Unity /// </summary> public void ButtonUpClick() { if (m_thisItem.Upgrade()) { if (m_thisItem.GetType() == typeof(Science)) { m_people.MakeBoost(); GameAbstractItem itm = m_thisItem as GameAbstractItem; if (itm != null) { while (itm.m_workers > 0) { ButtonMinusClick(); } } foreach (ArrowScript asc in m_from) { asc.m_to.GetComponent <IconScript>().m_to.Remove(asc); Destroy(asc.gameObject); } foreach (ArrowScript asc in m_to) { asc.m_from.GetComponent <IconScript>().m_from.Remove(asc); Destroy(asc.gameObject); } MainScript.m_sAllItems.Remove(gameObject); MainScript.m_sIsButtonPressed = false; Destroy(gameObject); } } }
/// <summary> /// Add production into dictionary by ItemsEffect.name /// </summary> /// <param name="prod"> production </param> public static void AddProduction(GameAbstractItem prod, string effectName) { GetProd(effectName).m_productions.Add(prod); }
/// <summary> /// Move arrows and change colors /// </summary> void Update() { try { if (!TimeScript.m_isItPaused && !m_isItPaused) { //position of one of the end object has changed if (m_from != null && m_to != null && (m_from.transform.position != _fromCoord || m_to.transform.position != _toCoord)) { MoveArrow(); } SpriteRenderer rend = _bodyRender; SpriteRenderer rendBody = _bodyRender2; GameAbstractItem itm = m_to.m_thisItem as GameAbstractItem; GameMaterial matFrom = m_from.m_thisItem as GameMaterial; if (m_isItTool) { Color clr = rend.color; if (m_from.m_thisItem.m_count > 0) { clr = _sArrowToolsEnough; } else { clr = _sArrowToolsNotEnough; } if (!clr.Equals(rend.color)) { if (_isItHimself) { _arrowBody2.color = clr; _arrowBody3.color = clr; } else { rend.color = clr; } } } else if (itm != null && (itm.m_workers == 0)) { rend.color = _sArrowMaterialsNotUsed; } else if (matFrom != null && matFrom.m_productivity < 0) { rend.color = _sArrowMaterialsNotEnough; } else { rend.color = _sArrowMaterialsEnough; } rendBody.color = rend.color; } } catch (Exception ex) { Debug.LogError("ArrowScript update exception:" + ex.Message); } }