コード例 #1
0
ファイル: HlObj.cs プロジェクト: thegamedesigner/cff
    public void CmdCreateObj(int clId, Vector3 pos, int objType)    //Sends an order from the client to the server
    {
        int uId = ObjFuncs.GetUniqueId();

        ChatScript.ChatLocally("CreateObj on Sv. uId: " + uId);
        RpcCreateObj(clId, pos, objType, uId);
    }
コード例 #2
0
    public void RpcUpdateHealth(int clId, int uId, int hp)    //Sv to clients
    {
        //Added this to the gamestate tick. Don't think this is needed.
        int index = ObjFuncs.GetObjIndexForUID(uId);

        ObjFuncs.objs[index].health = hp;
    }
コード例 #3
0
    public void RpcCreateObj(int clId, Vector3 pos, int objType, int uId)
    {
        //create the object on all clients
        ChatScript.ChatLocally("CreateObj on Cl. uId: " + uId);
        //Trigger local effect
        Effects.CircleBlip(pos, 3, 6, 1);

        //Create the correct object of type
        ObjFuncs.CreateObj((ObjFuncs.Type)objType, pos, Vector3.zero, clId, uId);
    }
コード例 #4
0
 public static void UpdateServer()    //Called by the server's version of the network manager object
 {
     if (hl.peers != null)
     {
         for (int i = 0; i < hl.peers.Count; i++)
         {
             Resources.UpdateResources(hl.peers[i]);
         }
     }
     ObjFuncs.UpdateObjsOnServer();
 }
コード例 #5
0
ファイル: Ticks.cs プロジェクト: thegamedesigner/vrt
    public static void ApplyObjHealth(int uId, int health)
    {
        //Apply this to an object's goal
        int index = ObjFuncs.GetObjIndexForUID(uId);

        if (index == -1)
        {
            return;
        }                                   //Couldn't find the obj
        if (ObjFuncs.objs[index] == null)
        {
            return;
        }                                                    //Somehow, this obj[index] contains a null?

        ObjFuncs.objs[index].health = health;
    }
コード例 #6
0
ファイル: Ticks.cs プロジェクト: thegamedesigner/vrt
    public static void ApplyObjGoal(int uId, Vector3 goal)
    {
        //Apply this to an object's goal
        int index = ObjFuncs.GetObjIndexForUID(uId);

        if (index == -1)
        {
            return;
        }                                   //Couldn't find the obj
        if (ObjFuncs.objs[index] == null)
        {
            return;
        }                                                    //Somehow, this obj[index] contains a null?

        ObjFuncs.objs[index].goal = goal;
        xa.goal      = goal;
        xa.debugStr += "\nReceived goal";
    }
コード例 #7
0
    void Update()
    {
        Effects.UpdateEffects();

        if (xa.lastGoal.x != xa.goal.x && xa.lastGoal.z != xa.goal.z)
        {
            xa.lastGoal = xa.goal;
            if (xa.de.debugText.text.Length > 700)
            {
                xa.de.debugText.text = "";
            }
            xa.de.debugText.text += "\nGoal: " + xa.goal;
        }

        if (Input.GetKeyDown(KeyCode.T))
        {
            ObjFuncs.CreateAllGrids();
        }
    }
コード例 #8
0
ファイル: Ticks.cs プロジェクト: thegamedesigner/cff
    //Called on the client, applys these changes to the objects
    public static void ApplyTickOnClient(GameState g)
    {
        //Create a temp list to fill
        List <GameItem> items = new List <GameItem>();

        //fill the list
        for (int i = 0; i < g.items.Length; i++)
        {
            GameItem gi = new GameItem();
            gi.uId      = g.items[i].uId;
            gi.syncdVar = g.items[i].syncdVar;
            gi.newValue = g.items[i].newValue;
            items.Add(gi);
        }
        ObjFuncs.Obj o;

        //go through every item in the lists
        for (int i = 0; i < items.Count; i++)
        {
            //find the object, by looping through all objects and comparing the ID

            int index = ObjFuncs.GetObjIndexForUID(items[i].uId);
            if (index != -1)
            {
                if (ObjFuncs.objs[index] != null)
                {
                    o = ObjFuncs.objs[index];

                    //now apply to the objs. (doesn't always have to apply directly to the source variable. It could sync from pos to desiredPos, for example, and assume the unit will handle that itself.
                    switch ((SyncdVars)items[i].syncdVar)
                    {
                    case SyncdVars.Goal:
                        float[] v = items[i].newValue;
                        o.goal  = new Vector3((float)v[0], (float)v[1], (float)v[2]);
                        xa.goal = o.goal;
                        xa.de.debugText.text += "\nReceived goal";
                        break;
                    }
                }
            }
        }
    }
コード例 #9
0
    public void CmdCreateObj(int clId, Vector3 pos, int objType)    //Sends an order from the client to the server
    {
        Debug.Log("Trying to buy " + (ObjFuncs.Type)objType);
        //Can the player afford this object?
        hl.Peer p = hl.GetPeerForUID(clId);
        if (p == null)
        {
            Debug.Log("Peer (" + clId + ") was null, failed to buy " + (ObjFuncs.Type)objType); return;
        }                                                                                                                     //Make sure the peer still exists
        if (!ObjFuncs.CheckCost((ObjFuncs.Type)objType, p))
        {
            Debug.Log("Couldnt afford " + (ObjFuncs.Type)objType); return;
        }                                                 //Make sure they can afford this obj

        ObjFuncs.SubtractCost((ObjFuncs.Type)objType, p); //Spend the money to buy this object

        hl.uIds++;                                        //Only ever do this on the server
        int uId = hl.uIds;

        ChatScript.ChatLocally("CreateObj on Sv. uId: " + uId);
        RpcCreateObj(clId, pos, objType, uId);
    }
コード例 #10
0
    public static void UpdateClient()
    {
        ManageGame();                 //Handle game logic, what little needs to happen on the client-side

        ObjFuncs.UpdateObjsLocally(); //Handles objs locally.
    }
コード例 #11
0
ファイル: ServerSideLoop.cs プロジェクト: thegamedesigner/cff
 public static void HandleSvGameplayLogic()
 {
     ObjFuncs.UpdateObjsOnServer();
 }
コード例 #12
0
    public static List <ObjFuncs.Obj> gridObjs; //Objs that the dragged object is checking against their grids

    public static void InputOrders()            //Called every frame from hl.HlObj Update
    {
        //There is a generic way to do this, but for now, I'm just going to handle each case

        //Make sure that the connection isn't null
        if (hl.hlObj == null)
        {
            return;
        }

        //Get mouse pos in the world
        Vector3    mousePos = Vector3.zero;
        Ray        ray      = xa.de.globalMainCam.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, 999, xa.de.toHitFloorMask))
        {
            mousePos = hit.point;
        }

        MouseOrders mouseOrder = MouseOrders.None;

        if (Input.GetMouseButtonDown(0))        //Left click - Drag selection or drag object?
        {
            //is the mouse over a object that can be dragged?
            draggingObj = -1;
            ray         = xa.de.globalMainCam.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit, 999, xa.de.toHitDraggableObjs))
            {
                //An obj is under the mouse,
                int uId   = hit.collider.gameObject.GetComponent <HitboxScript>().go.GetComponent <Info>().uId;
                int index = ObjFuncs.GetObjIndexForUID(uId);

                //can it be dragged?
                if (!ObjFuncs.objs[index].isUnit && ObjFuncs.objs[index].attachedTo == -1)
                {
                    mouseOrder  = MouseOrders.DraggingObj_Start;
                    draggingObj = uId;
                    ObjFuncs.PickingUpAnObj(draggingObj);
                }
            }


            if (draggingObj == -1)
            {
                //No object under my mouse, so start dragging a selection box
                mouseOrder = MouseOrders.SelectionBox_StartDragging;
            }
        }
        if (Input.GetMouseButtonUp(0))        //Left click up, release dragged object or stop selection box?
        {
            if (draggingObj != -1)            //I was dragging an obj. Drop it.
            {
                //Dropping an object
                mouseOrder = MouseOrders.DraggingObj_Stop;

                ObjFuncs.DroppingAnObj(draggingObj);

                draggingObj = -1;
            }
            else
            {
                //I wasn't dragging an obj, so I must have been dragging a selection box
                mouseOrder = MouseOrders.SelectionBox_StopDragging;
            }
        }
        if (draggingObj != -1)        //Dragging an object
        {
            int index = ObjFuncs.GetObjIndexForUID(draggingObj);
            ObjFuncs.objs[index].go.transform.SetX(mousePos.x);
            ObjFuncs.objs[index].go.transform.SetZ(mousePos.z);

            ObjFuncs.objs[index].visualState[0] = 0;
            int result = ObjFuncs.IfOverValidPos(draggingObj);
            if (result != -1)
            {
                //change color
                ObjFuncs.objs[index].visualState[0] = 1;

                //Align to the possible gridObj's angle
                int gridObjIndex = ObjFuncs.GetObjIndexForUID(result);
                ObjFuncs.objs[index].desiredAngle = ObjFuncs.objs[gridObjIndex].go.transform.localEulerAngles.y;
            }

            //snap to this (tween later)
            ObjFuncs.objs[index].go.transform.SetAngY(ObjFuncs.objs[index].desiredAngle + ObjFuncs.objs[index].gridObjAnglesOffset);

            //detect if the player wants to rotate this object
            if (Input.GetKeyDown(KeyCode.Q))            //Rotate the object
            {
                ObjFuncs.objs[index].gridObjAnglesOffset -= 90;
            }
            if (Input.GetKeyDown(KeyCode.E))            //Rotate the object
            {
                ObjFuncs.objs[index].gridObjAnglesOffset += 90;
            }
        }

        SelectionScript.HandleSelection(mouseOrder);        //Handles local selection box

        //Issue a move command to all selected units of the correct player
        if (Input.GetMouseButtonDown(1))        //Move order
        {
            //Send the order to the server. Fire and forget!
            ObjFuncs.Obj o;

            //send one order per unit ordered.
            List <int> result = new List <int>();
            for (int i = 0; i < ObjFuncs.objs.Count; i++)
            {
                o = ObjFuncs.objs[i];
                if (o.isUnit && o.ownedByClId == hl.local_uId && o.selected)
                {
                    result.Add(o.uId);
                }
            }
            int[] unitIds = new int[result.Count];
            for (int i = 0; i < result.Count; i++)
            {
                unitIds[i] = result[i];
            }                                                                             //write to the array

            hl.hlObj.CmdMoveOrder(hl.local_uId, mousePos, unitIds);

            //Trigger local effect
            Effects.MoveOrderEffect(mousePos);
        }

        //This is currently hardwired to specific keys, but later players will be able to rebind.
        if (Input.GetKeyDown(KeyCode.Alpha1))        //Create a command pod!
        {
            ChatScript.ChatLocally("Detected local createObj order: Command Pod");
            //Send the order to the server
            hl.hlObj.CmdCreateObj(hl.local_uId, mousePos, (int)ObjFuncs.Type.CommandPod);

            //Trigger local effect
            //Effects.CircleBlip(mousePos, 5, 5);
        }
        if (Input.GetKeyDown(KeyCode.Alpha2))        //Create a hull block
        {
            ChatScript.ChatLocally("Detected local createObj order: Hull Block");
            //Send the order to the server
            hl.hlObj.CmdCreateObj(hl.local_uId, mousePos, (int)ObjFuncs.Type.HullBlock);

            //Trigger local effect
            //Effects.CircleBlip(mousePos, 5, 5);
        }
        if (Input.GetKeyDown(KeyCode.Alpha3))        //Create an engine
        {
            ChatScript.ChatLocally("Detected local createObj order: Engine");
            //Send the order to the server
            hl.hlObj.CmdCreateObj(hl.local_uId, mousePos, (int)ObjFuncs.Type.Engine);

            //Trigger local effect
            //Effects.CircleBlip(mousePos, 5, 5);
        }
        if (Input.GetKeyDown(KeyCode.Alpha4))        //Create a gun
        {
            ChatScript.ChatLocally("Detected local createObj order: Gun");
            //Send the order to the server
            hl.hlObj.CmdCreateObj(hl.local_uId, mousePos, (int)ObjFuncs.Type.Gun);

            //Trigger local effect
            //Effects.CircleBlip(mousePos, 5, 5);
        }
    }