public MainViewModel()
        {
            try
            {
                productCommands = new ProductCommands(_connectionString);
                Products.AddRange(productCommands.GetList());

                ProdCategoryCommands prodCategoryCommands = new ProdCategoryCommands(_connectionString);
                ProdCategories.AddRange(prodCategoryCommands.GetList());

                LocationCommands locationCommands = new LocationCommands(_connectionString);
                Locations.AddRange(locationCommands.GetList());

                LocCategoryCommands locCategoryCommands = new LocCategoryCommands(_connectionString);
                LocationCategories.AddRange(locCategoryCommands.GetList());

                UnitCommands unitCommands = new UnitCommands(_connectionString);
                Units.AddRange(unitCommands.GetList());

                UpdateAppStatus($"Database tables fetched.", Brushes.DarkGreen);
            }
            catch (Exception ex) { UpdateAppStatus($"Error on retrieving tables from SQL database:\n{ex.Message}", Brushes.Red); }

            GenerateTableProductsToDisplay();
            InitializeAllPropertyFields();
            Scheduler();
        }
示例#2
0
            static void Postfix(UnitCommand cmd, ref UnitCommands.CustomHandlerData?customHandler)
            {
                if (Mod.Enabled && FixKineticistWontStopPriorCommand &&
                    customHandler.HasValue && (customHandler.Value.ExecuteBefore ?? cmd) != cmd)
                {
                    UnitCommands commands = cmd.Executor.Commands;

                    // remove conflicting command
                    UnitCommand prior = commands.Raw[(int)cmd.Type] ?? commands.GetPaired(cmd);
                    if (Game.Instance.IsPaused && commands.PreviousCommand == null && prior != null && prior.IsRunning)
                    {
                        commands.PreviousCommand = prior;
                        commands.PreviousCommand.SuppressAnimation();
                        commands.Raw[(int)commands.PreviousCommand.Type] = null;
                    }
                    else
                    {
                        commands.InterruptAndRemoveCommand(cmd.Type);
                    }

                    // update target
                    if (cmd.Type == UnitCommand.CommandType.Standard || commands.Standard == null)
                    {
                        commands.UpdateCombatTarget(cmd);
                    }
                }
            }
示例#3
0
 private void OnTriggerEnter(Collider other)
 {
     if (_currentCommand == UnitCommands.Attack)
     {
         Unit otherUnit = other.gameObject.GetComponent <Unit>();
         if (otherUnit != null)
         {
             TcpServer.Instance.DestroyUnit(otherUnit.gameObject.GetComponent <NetworkingObject>().GetObjectID());
             _currentTarget     = null;
             _currentCommand    = UnitCommands.None;
             _targetDestination = transform.position;
             gameObject.GetComponent <NavMeshAgent>().SetDestination(_targetDestination);
         }
     }
 }
示例#4
0
    public static GameObject Decorate(GameObject obj)
    {
        UnitCommands command = obj.GetComponent <CommandUiSender>().GetCommand().GetUnitCommand();

        switch (command)
        {
        case (UnitCommands.Move):
            obj.GetComponent <Button>().GetComponentInChildren <Text>().text = "Move";
            break;

        case (UnitCommands.Hold):
            obj.GetComponent <Button>().GetComponentInChildren <Text>().text = "Stop";
            break;
        }

        return(obj);
    }
示例#5
0
 public void SendCommand(Commands command, UnitCommands unitCommand, int objectID, List <float> commandData, bool sendNetworkID)
 {
     _writer.Write((int)command);
     if (unitCommand != UnitCommands.None)
     {
         _writer.Write((int)unitCommand);
     }
     _writer.Write(objectID);
     if (commandData != null)
     {
         foreach (float t in commandData)
         {
             _writer.Write((double)t);
         }
     }
     if (sendNetworkID)
     {
         _writer.Write(_networkID);
     }
 }
    public void HandleCommand(Commands command, BinaryReader reader)
    {
        switch (command)
        {
        case Commands.Update:
            UnitCommands uCommand = (UnitCommands)reader.ReadInt32();
            int          objectID;
            GameObject   obj;
            GameObject   targetObj;
            Unit         unit;
            switch (uCommand)
            {
            case UnitCommands.Walk:
                objectID = reader.ReadInt32();
                obj      = GetObjectWithID(objectID);
                if (obj != null)
                {
                    unit = obj.GetComponent <Unit>();
                    unit.SetCurrentTarget(null);
                    float xGoalPos = (float)reader.ReadDouble();
                    float zGoalPos = (float)reader.ReadDouble();
                    obj.GetComponent <NavMeshAgent>().SetDestination(new Vector3(xGoalPos, 0.5f, zGoalPos));
                }
                break;

            case UnitCommands.Attack:
                objectID = reader.ReadInt32();
                obj      = GetObjectWithID(objectID);
                if (obj != null)
                {
                    targetObj = GetObjectWithID(reader.ReadInt32());
                    unit      = obj.GetComponent <Unit>();
                    unit.SetCurrentCommand(UnitCommands.Attack);
                    unit.SetCurrentTarget(targetObj);
                    unit.SetCurrentTargetDestination(targetObj.transform.position);
                    obj.GetComponent <NavMeshAgent>().SetDestination(targetObj.transform.position);
                }
                break;

            case UnitCommands.Follow:
                objectID = reader.ReadInt32();
                obj      = GetObjectWithID(objectID);
                if (obj != null)
                {
                    targetObj = GetObjectWithID(reader.ReadInt32());
                    unit      = obj.GetComponent <Unit>();
                    unit.SetCurrentCommand(UnitCommands.Follow);
                    unit.SetCurrentTarget(targetObj);
                    unit.SetCurrentTargetDestination(targetObj.transform.position);
                    obj.GetComponent <NavMeshAgent>().SetDestination(targetObj.transform.position);
                }
                break;
            }
            break;

        case Commands.Create:
            SpawnLocalObject(reader);
            break;

        case Commands.Destroy:
            DestroyLocalObject(reader);
            break;

        case Commands.Disconnect:
            //TODO:
            break;

        case Commands.Unknown:
            //TODO:
            break;
        }
    }
示例#7
0
 public void SetCurrentCommand(UnitCommands command)
 {
     _currentCommand = command;
 }
示例#8
0
 // Start is called before the first frame update
 void Start()
 {
     _currentCommand    = UnitCommands.None;
     _targetDestination = transform.position;
     _currentTarget     = null;
 }
示例#9
0
 public void SetUnitCommand(UnitCommands newCommand)
 {
     unitCommand = newCommand;
 }
示例#10
0
    public void UpdateObject(BinaryReader reader, List <BinaryWriter> writers, List <GameObject> objectList, Text text)
    {
        UnitCommands uc = (UnitCommands)reader.ReadInt32();

        text.text += " " + uc;
        //get object
        int        objectID       = reader.ReadInt32();
        GameObject objectToUpdate = GetObjectWithID(objectID, objectList);

        text.text += " updating object with ID: " + objectID;

        if (objectToUpdate == null)
        {
            return;
        }

        Unit unit;

        text.text += " updating its destination";
        bool success;

        switch (uc)
        {
        case UnitCommands.Walk:
            //get the x and z coordinates
            float   xGoalPos       = (float)reader.ReadDouble();
            float   zGoalPos       = (float)reader.ReadDouble();
            Vector3 positionVector = new Vector3(xGoalPos, 0.5f, zGoalPos);
            text.text += positionVector.x + " " + positionVector.z + " ";

            success    = objectToUpdate.GetComponent <NavMeshAgent>().SetDestination(positionVector);
            text.text += positionVector.x + " " + positionVector.z + " " + success;
            unit       = objectToUpdate.GetComponent <Unit>();
            unit.SetCurrentCommand(UnitCommands.Walk);
            unit.SetCurrentTargetDestination(positionVector);
            unit.SetCurrentTarget(null);

            text.text = success.ToString();

            if (success)
            {
                foreach (BinaryWriter writer in writers)
                {
                    writer.Write((int)Commands.Update);
                    writer.Write((int)UnitCommands.Walk);
                    writer.Write(objectID);
                    writer.Write((double)xGoalPos);
                    writer.Write((double)zGoalPos);
                }
            }
            break;

        case UnitCommands.Attack:
            int attackTargetObjectID = (int)reader.ReadDouble();

            GameObject attackObj = GetObjectWithID(attackTargetObjectID, objectList);

            if (attackObj != null)
            {
                unit = objectToUpdate.GetComponent <Unit>();
                unit.SetCurrentCommand(UnitCommands.Attack);
                unit.SetCurrentTarget(attackObj);
                unit.SetCurrentTargetDestination(attackObj.transform.position);
                success = objectToUpdate.GetComponent <NavMeshAgent>().SetDestination(attackObj.transform.position);

                if (success)
                {
                    foreach (BinaryWriter writer in writers)
                    {
                        writer.Write((int)Commands.Update);
                        writer.Write((int)UnitCommands.Attack);
                        writer.Write(objectID);
                        writer.Write(attackTargetObjectID);
                    }
                }
            }
            break;

        case UnitCommands.Follow:
            int targetObjectID = (int)reader.ReadDouble();

            GameObject obj = GetObjectWithID(targetObjectID, objectList);

            if (obj != null)
            {
                unit = objectToUpdate.GetComponent <Unit>();
                unit.SetCurrentCommand(UnitCommands.Follow);
                unit.SetCurrentTarget(obj);
                unit.SetCurrentTargetDestination(obj.transform.position);
                success = objectToUpdate.GetComponent <NavMeshAgent>().SetDestination(obj.transform.position);

                if (success)
                {
                    foreach (BinaryWriter writer in writers)
                    {
                        writer.Write((int)Commands.Update);
                        writer.Write((int)UnitCommands.Follow);
                        writer.Write(objectID);
                        writer.Write(targetObjectID);
                    }
                }
            }

            break;
        }

        //-----------------------------------------------------------------------
        //GameObject obj = GetObjectWithID(reader.ReadInt32(), objectList);
        //if (obj != null)
        //{
        //    obj.transform.Translate(0, (float)reader.ReadDouble(), 0);
        //}
        //else
        //{
        //    return;
        //}
        //foreach (BinaryWriter writer in writers)
        //{
        //    writer.Write((int)Commands.Update);
        //    writer.Write(obj.GetComponent<NetworkingObject>().GetObjectID());
        //    writer.Write((double)obj.transform.position.y);
        //}
    }
 public static bool IsRunning(this UnitCommands commands)
 {
     return(commands.Raw.Any(command => command != null && command.IsRunning));
 }
 public static UnitCommand GetPaired(this UnitCommands unitCommands, UnitCommand cmd)
 {
     return(GetMethod <UnitCommands, Func <UnitCommands, UnitCommand, UnitCommand> >("GetPaired")
                (unitCommands, cmd));
 }
 public static void UpdateCombatTarget(this UnitCommands unitCommands, UnitCommand cmd)
 {
     GetMethod <UnitCommands, Action <UnitCommands, UnitCommand> >("UpdateCombatTarget")(unitCommands, cmd);
 }
 public static void InterruptAndRemoveCommand(this UnitCommands unitCommands, UnitCommand.CommandType type)
 {
     GetMethod <UnitCommands, Action <UnitCommands, UnitCommand.CommandType> >
         ("InterruptAndRemoveCommand")(unitCommands, type);
 }