public void OnClickCraft() { PlayerCharacter player = PlayerCharacter.Get(); if (player.CanCraft(data)) { ItemData item = data.GetItem(); ConstructionData construct = data.GetConstruction(); PlantData plant = data.GetPlant(); if (item != null) { player.CraftItem(item); } if (construct != null) { player.SelectCraftConstruction(construct); } if (plant != null) { player.CraftPlant(plant); } craft_btn.interactable = false; Hide(); } }
/// <summary> /// Renders an Area chart a canvas. This method is called by the chart class. /// </summary> /// <param name="canvasWrapper">wrapper class containing info mation about the canvas and chart</param> /// <param name="axis">Axis orientation object</param> /// <param name="minMax">Data for the extreme values</param> /// <param name="gridPaint">Paint object for the grid lines</param> public override void RenderChart(CanvasWrapper canvasWrapper, Axis axis, IMinMax minMax) { CheckConstructionPolicy(nameof(LineChart)); if (canvasWrapper.NumberPlottedChart < 1) { DrawHorizontalLabels(canvasWrapper, axis, minMax); DrawVerticalLabels(canvasWrapper, axis, minMax); } var canvas = canvasWrapper.Canvas; var path = new SKPath(); var constructionPoints = ConstructionData.ToList(); var firstPoint = ConstructionData.First(); var lastPoint = ConstructionData.Last(); var connectionPoint = new SKPoint(lastPoint.X, firstPoint.Y); constructionPoints.Add(connectionPoint); path.MoveTo(constructionPoints.First()); foreach (var point in constructionPoints.Skip(1)) { path.LineTo(point); } path.FillType = SKPathFillType.EvenOdd; path.Close(); _chartPaint.IsStroke = false; canvas.DrawPath(path, _chartPaint); canvasWrapper.NumberPlottedChart += 1; if (canvasWrapper.CanShowLegend) { RenderLegend(canvasWrapper, axis, canvas, PointPlotVariant.AreaChart); } }
/// <summary> /// Converts a store node into an SSA value. /// </summary> private static void Convert( SSARewriterContext <Value> context, ConstructionData data, Store store) { if (!data.TryGetConverted(store.Target, out var storeRef)) { return; } Value ssaValue = store.Value; if (!storeRef.IsDirect) { ssaValue = context.GetValue(context.Block, storeRef.Source); ssaValue = context.Builder.CreateSetField( store.Location, ssaValue, storeRef.FieldSpan, store.Value); } context.SetValue(context.Block, storeRef.Source, ssaValue); context.Remove(store); }
//Create a totally new one that will be added to save file, already constructed public static Construction Create(ConstructionData data, Vector3 pos) { Construction construct = CreateBuildMode(data, pos); construct.FinishContruction(); return(construct); }
//Spawn an existing one in the save file (such as after loading) public static Construction Spawn(string uid) { BuiltConstructionData bdata = PlayerData.Get().GetConstructed(uid); if (bdata != null) { ConstructionData cdata = ConstructionData.Get(bdata.construction_id); if (cdata != null) { GameObject build = Instantiate(cdata.construction_prefab, bdata.pos, cdata.construction_prefab.transform.rotation); Construction construct = build.GetComponent <Construction>(); construct.data = cdata; construct.was_built = true; construct.unique_id.unique_id = uid; Destructible destruct = construct.GetComponent <Destructible>(); if (destruct != null) { destruct.was_built = true; } return(construct); } } return(null); }
public void AttackBuild(int _damage, string _ID, TemplateUnits _attacker) { ConstructionData data = this.FindBuild(_ID); data.currHealth -= _damage; if (data.currHealth <= 0) { this.DestroyBuild(data); data.currHealth = 0; } data.healthBar.SetHealthBar((float)data.currHealth / (float)data.totalHealth); this.AttackedObj(_ID, _attacker); float healthRangeSize = data.totalHealth / this.colorHealth.Count; int currHealthRange = Mathf.Clamp(Mathf.FloorToInt(data.currHealth / healthRangeSize), 0, this.colorHealth.Count - 1); if (currHealthRange >= this.colorHealth.Count) { currHealthRange = this.colorHealth.Count - 1; } data.currColor = this.colorHealth[currHealthRange]; }
/// <summary> /// Renders a line chart a canvas. This method is called by the chart class. /// </summary> /// <param name="canvasWrapper">wrapper class containing info mation about the canvas and chart</param> /// <param name="axis">Axis orientation object</param> /// <param name="minMax">Data for the extreme values</param> /// <param name="gridPaint">Paint object for the grid lines</param> public override void RenderChart(CanvasWrapper canvasWrapper, Axis axis, IMinMax minMax) { CheckConstructionPolicy(nameof(LineChart)); var canvas = canvasWrapper.Canvas; if (canvasWrapper.NumberPlottedChart < 1) { DrawHorizontalLabels(canvasWrapper, axis, minMax); DrawVerticalLabels(canvasWrapper, axis, minMax); } _chartPaint.IsStroke = true; var path = new SKPath(); path.MoveTo(ConstructionData.First()); foreach (var point in ConstructionData.Skip(1)) { path.LineTo(point); if (ShowPoints) { canvas.DrawCircle(point, PointRadius, _chartPaint); } } canvas.DrawPath(path, _chartPaint); canvasWrapper.NumberPlottedChart += 1; if (canvasWrapper.CanShowLegend) { RenderLegend(canvasWrapper, axis, canvas, PointPlotVariant.LineChart); } }
//Ensures that charts are constructed through the Chart<T> class protected void CheckConstructionPolicy(string chartName) { if (ConstructionData == null || ConstructionData.Count() < 1) { throw new SelfConstructionException(chartName); } }
public static void Load() { craft_data.Clear(); craft_data.AddRange(ItemData.GetAll()); craft_data.AddRange(ConstructionData.GetAll()); craft_data.AddRange(PlantData.GetAll()); }
/// <summary> /// Renders a bar chart on the canvas. This method is called by the Chart class. /// </summary> /// <param name="canvasWrapper">wrapper class containing info mation about the canvas and chart</param> /// <param name="axis">Axis orientation object</param> /// <param name="minMax">Data for the extreme values</param> /// <param name="gridPaint">Paint object for the grid lines</param> public override void RenderChart(CanvasWrapper canvasWrapper, Axis axis, IMinMax minMax) { CheckConstructionPolicy(nameof(BarChart)); var drawingSpace = canvasWrapper.ChartArea.Right / ConstructionData.Count() * 0.9; var rectSpace = (float)drawingSpace / canvasWrapper.NumberOfCharts; var columnSpace = (float)((canvasWrapper.ChartArea.Right / ConstructionData.Count()) - drawingSpace) / 2; var pointX = canvasWrapper.ChartArea.Width / ConstructionData.Count(); var counter = 0; foreach (var point in ConstructionData) { var x1 = (pointX * counter) + canvasWrapper.ChartArea.Left + columnSpace + (canvasWrapper.NumberPlottedChart * rectSpace); var x2 = x1 + rectSpace - columnSpace; var rect = new SKRect(x1, point.Y, x2, canvasWrapper.ChartArea.Top); _chartPaint.IsStroke = IsStroked; canvasWrapper.Canvas.DrawRect(rect, _chartPaint); var xLabel = XLabel[counter]; axis.DrawAndPositionXTickMark(xLabel, (x1 + (x2 - x1) / 2), canvasWrapper.ChartArea.Bottom, _labelPaint); var yLabel = GetYLabel(OriginalData.ElementAt(counter).Y); axis.DrawAndPositionYTickMark(yLabel, point.Y, (x1 + (x2 - x1) / 2), _labelPaint); counter++; } canvasWrapper.NumberPlottedChart += 1; }
public override void Execute(TemplateControllerCustom _controller, float _delta = 0) { if (!_controller.gameObject.activeSelf) { return; } TemplateUnits unit = _controller as TemplateUnits; if (unit.targetPosition == vectorZero) { if (checkIsAlive) { if (!CityMaster.instance.IsBuildAlive(this.buildTag)) { return; } } if (CityMaster.instance.HasFreeSlot(this.buildTag)) { ConstructionData data = CityMaster.instance.FindBuild(this.buildTag); unit.targetPosition = data.obj.transform.position; unit.targetPosition.y = _controller.transform.position.y; unit.targetBuild = this.buildTag; unit.targetBuildData = data; unit.agent.SetDestination(unit.targetPosition); } } }
public void RequestBuildDirector_RequestBuilder_Parameters() { var director = new RequestBuildDirector <MockParameters>( new RequestBuilder <MockModule, MockParameters>() ); var value = "https://api.vk.com/method/" + $"mockModule.method?name=victor&age=20&" + $"access_token={AccessToken}&v={Version}"; var parameters = new MockParameters { Name = "victor", Age = 20 }; var data = new ConstructionData <MockParameters> { AccessToken = AccessToken, Version = Version, MethodName = nameof(MockModule.Method), Parameters = parameters }; var request = director.Construct(data); Assert.Equal(data.MethodName, request.MethodName); Assert.Equal(data.Version, request.Version); Assert.Equal(value, request.Value); }
public static ConstructionBehaviour CreateConstructionBehaviour(ConstructionData constructionData) { ConstructionBehaviour constructionBehaviour = Instantiate(constructionData.Prefab).AddComponent <ConstructionBehaviour>(); constructionBehaviour.Initialize(constructionData, constructionBehaviour.GetComponent <IConstructable>()); return(constructionBehaviour); }
public IRequestBuilder <TParameters> Initialize(ConstructionData <TParameters> data) { Data = data ?? throw new ArgumentNullException(nameof(data)); StringBuilder = new StringBuilder(); return(this); }
void Awake() { _instance = this; ItemData.Load(items_folder); ConstructionData.Load(constructions_folder); PlantData.Load(plants_folder); CraftData.Load(); }
private static bool IsCandidateCtor(MethodBase ctor, ConstructionData <MethodInfo> candidateFactoryMethod) { var ctorCarameters = ctor.GetParameters(); return(((candidateFactoryMethod == null) || (candidateFactoryMethod.ParameterCount < ctorCarameters.Length)) && IsNotCopyConstructor(ctor.DeclaringType, ctorCarameters)); }
public void SelectCraftConstruction(ConstructionData item) { current_construction = Construction.CreateBuildMode(item, transform.position); current_construction.StartConstruction(); clicked_build = false; TheAudio.Get().PlaySFX("craft", item.craft_sound); }
public void StartPlacement(ConstructionData constructionData) { if (!IsInvoking()) { _constructionBehaviour = CreateConstructionBehaviour(constructionData); InvokeRepeating(nameof(Routine), 0, Constant.DEFAULT_REFRESH_RATE); } }
/// <summary> /// Default constructor /// </summary> public Primitive() { Flexible = new FlexibleData(); Light = new LightData(); LightMap = new LightImage(); Sculpt = new SculptData(); PrimData = new ConstructionData(); PhysicsProps = new PhysicsProperties(); }
public void DestroyBuild(ConstructionData _data) { for (int count = 0; count < _data.unitsInside.Count; count++) { this.RemoveFromBuild(_data.ID, _data.unitsInside[count]); } _data.uiMapElement.SetActive(false); _data.obj.SetActive(false); }
public bool HasFreeSlot(string _ID) { ConstructionData data = this.FindBuild(_ID); if (data.unitsInside.Count < data.totalUnits) { return(true); } return(false); }
public Request Construct(ConstructionData <TParameters> data) { return(Builder .Initialize(data) .BuildPath() .BuildSection() .BuildQuestionMark() .BuildParameters() .BuildDuty() .GetRequest()); }
public bool RemoveFromBuild(string _ID, TemplateUnits _unit) { ConstructionData data = this.FindBuild(_ID); if (data.unitsInside.Contains(_unit)) { data.unitsInside.Remove(_unit); return(true); } return(false); }
private static ConstructionData <ConstructorInfo>[] GetGreediestAvailableNewings( IEnumerable <ConstructorInfo> constructors, ConstructionKey key, ConstructionData <MethodInfo> greediestUnconditionalFactory) { var candidateConstructors = constructors .Filter(ctor => IsCandidateCtor(ctor, greediestUnconditionalFactory)); return(CreateConstructionData( candidateConstructors, ctor => new ConstructionData <ConstructorInfo>(ctor, Expression.New, key, priority: 0))); }
public bool HideInBuild(string _ID, TemplateUnits _unit) { ConstructionData data = this.FindBuild(_ID); if (data.currUnits < data.totalUnits) { data.unitsInside.Add(_unit); return(true); } return(false); }
private ItemCost GetCost(ConstructionData data) { Dictionary <string, int> resources = data.GetTotalCost(); ItemCost cost = new ItemCost(); cost.wood = resources.ContainsKey("Wood") ? resources["Wood"] : 0; cost.wheat = resources.ContainsKey("Wheat") ? resources["Wheat"] : 0; cost.stone = resources.ContainsKey("Stone") ? resources["Stone"] : 0; cost.iron = resources.ContainsKey("Iron") ? resources["Iron"] : 0; cost.gold = resources.ContainsKey("Gold") ? resources["Gold"] : 0; cost.crystal = resources.ContainsKey("Crystal") ? resources["Crystal"] : 0; return(cost); }
/// <summary> /// Converts an address-space cast into an SSA binding. /// </summary> private static void Convert( SSARewriterContext <Value> context, ConstructionData data, AddressSpaceCast addressSpaceCast) { if (!data.TryGetConverted(addressSpaceCast.Value, out var castRef)) { return; } data.AddConverted(addressSpaceCast, castRef); context.Remove(addressSpaceCast); }
public void CreateButton(ConstructionData constructionData) { GameObject parent = new GameObject(); parent.gameObject.name = constructionData.name; parent.transform.SetParent(transform); parent.AddComponent<Button>().onClick.AddListener(() => OnClick(constructionData.name)); parent.AddComponent<Image>().sprite = constructionData.Sprite; GameObject child = new GameObject(); Text text = child.AddComponent<Text>(); text.text = constructionData.name; text.font = Resources.GetBuiltinResource<Font>("Arial.ttf"); text.fontSize = 24; text.alignment = TextAnchor.MiddleCenter; text.color = Color.black; child.transform.SetParent(parent.transform); }
/// <summary> /// Converts a field-address operation into an SSA binding. /// </summary> private static void Convert( SSARewriterContext <Value> context, ConstructionData data, LoadFieldAddress loadFieldAddress) { if (!data.TryGetConverted(loadFieldAddress.Source, out var fieldRef)) { return; } data.AddConverted( loadFieldAddress, fieldRef.Access(loadFieldAddress.FieldSpan)); context.Remove(loadFieldAddress); }
//Use an item in your inventory and build it on the map public void BuildItem(int slot, Vector3 pos) { InventoryItemData invdata = PlayerData.Get().GetItemSlot(slot); ItemData idata = ItemData.Get(invdata.item_id); if (idata != null) { ConstructionData construct = idata.construction_data; if (construct != null) { PlayerData.Get().RemoveItemAt(slot, 1); Construction.Create(construct, pos); TheUI.Get().CancelSelection(); } } }