Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Google.Protobuf.Collections;
- using SC2API_CSharp;
- using SC2APIProtocol;
- using SC2Bot.Controllers;
- using System.Collections.Generic;
- using System.Linq;
- using System.Numerics;
- using Action = SC2APIProtocol.Action;
- namespace SC2Bot
- {
- public class Unit
- {
- private SC2APIProtocol.Unit original;
- public UnitTypeData UnitTypeData => BaseController.GameData.Units[(int)UnitTypeID];
- public string Name => UnitTypeData.Name;
- public uint UnitTypeID => original.UnitType;
- public float Integrity => (original.Health + original.Shield) / (original.HealthMax + original.ShieldMax);
- public Vector3 Position => original.Pos.ToVector3();
- public Point WorldPosition => original.Pos;
- public ulong Tag => original.Tag;
- public float BuildProgress => original.BuildProgress;
- public UnitOrder Order => original.Orders.FirstOrDefault() ?? new UnitOrder();
- public RepeatedField<UnitOrder> Orders => original.Orders;
- public int Supply => (int)UnitTypeData.FoodRequired;
- public bool IsVisible => original.DisplayType == DisplayType.Visible;
- public int IdealWorkers => original.IdealHarvesters;
- public int AssignedWorkers => original.AssignedHarvesters;
- public bool MissingWorkers { get; set; } = true;
- public Alliance Alliance => original.Alliance;
- public RepeatedField<uint> Buffs => original.BuffIds;
- public float Energy => original.Energy;
- public RepeatedField<Attribute> Attributes => UnitTypeData.Attributes;
- public Unit(SC2APIProtocol.Unit unit)
- {
- Update(unit);
- }
- public void Update(SC2APIProtocol.Unit unit)
- {
- original = unit;
- }
- public double GetDistance(Unit otherUnit)
- {
- return Vector3.Distance(Position, otherUnit.Position);
- }
- public double GetDistanceSquared(Unit otherUnit)
- {
- return Vector3.DistanceSquared(Position, otherUnit.Position);
- }
- public double GetDistanceSquared(Vector3 location)
- {
- return Vector3.DistanceSquared(Position, location);
- }
- public double GetDistance(Vector3 location)
- {
- return Vector3.Distance(Position, location);
- }
- public void Train(uint unitType, bool queue = false)
- {
- if (!queue && Orders.Count > 0)
- return;
- var abilityID = Abilities.GetID(unitType);
- var action = UnitController.CreateRawUnitCommand(abilityID);
- action.ActionRaw.UnitCommand.UnitTags.Add(Tag);
- BaseController.Actions.Add(action);
- }
- public void UseAbility(uint abilityID, Unit targetUnit)
- {
- var constructAction = UnitController.CreateRawUnitCommand(abilityID);
- constructAction.ActionRaw.UnitCommand.UnitTags.Add(Tag);
- constructAction.ActionRaw.UnitCommand.TargetUnitTag = targetUnit.Tag;
- BaseController.Actions.Add(constructAction);
- }
- private void FocusCamera()
- {
- var action = new Action();
- action.ActionRaw = new ActionRaw();
- action.ActionRaw.CameraMove = new ActionRawCameraMove();
- action.ActionRaw.CameraMove.CenterWorldSpace = new Point();
- action.ActionRaw.CameraMove.CenterWorldSpace.X = Position.X;
- action.ActionRaw.CameraMove.CenterWorldSpace.Y = Position.Y;
- action.ActionRaw.CameraMove.CenterWorldSpace.Z = Position.Z;
- BaseController.Actions.Add(action);
- }
- public void Move(Vector3 target)
- {
- var action = UnitController.CreateRawUnitCommand(Abilities.MOVE);
- action.ActionRaw.UnitCommand.TargetWorldSpacePos = new Point2D();
- action.ActionRaw.UnitCommand.TargetWorldSpacePos.X = target.X;
- action.ActionRaw.UnitCommand.TargetWorldSpacePos.Y = target.Y;
- action.ActionRaw.UnitCommand.UnitTags.Add(Tag);
- BaseController.Actions.Add(action);
- }
- public void Attack(Vector3 target)
- {
- var action = UnitController.CreateRawUnitCommand(Abilities.ATTACK);
- action.ActionRaw.UnitCommand.TargetWorldSpacePos = new Point2D();
- action.ActionRaw.UnitCommand.TargetWorldSpacePos.X = target.X;
- action.ActionRaw.UnitCommand.TargetWorldSpacePos.Y = target.Y;
- action.ActionRaw.UnitCommand.UnitTags.Add(Tag);
- BaseController.Actions.Add(action);
- }
- public void Research(int researchType)
- {
- var research = UnitController.GameData.Upgrades[researchType];
- var abilityID = research.AbilityId;
- var action = UnitController.CreateRawUnitCommand(abilityID);
- action.ActionRaw.UnitCommand.UnitTags.Add(Tag);
- BaseController.AddAction(action);
- }
- public void Smart(Unit unit)
- {
- var action = UnitController.CreateRawUnitCommand(Abilities.SMART);
- action.ActionRaw.UnitCommand.TargetUnitTag = unit.Tag;
- action.ActionRaw.UnitCommand.UnitTags.Add(Tag);
- BaseController.Actions.Add(action);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment