Exemplo n.º 1
0
    //----------------------------------------------------------------------------------------------------------------
    // detect collisions

    void OnCollisionEnter(Collision collision)
    {
        if (debug)
        {
            Debug.Log(CTunity.fullName(gameObject) + ", Collision with: " + CTunity.fullName(collision.collider.gameObject));
        }
        if (!showHP)
        {
            return;
        }

        ScoreBoard tkso = collision.collider.gameObject.GetComponent <ScoreBoard>();

        if (debug)
        {
            //           Debug.Log(gameObject.name + ", activePlayer: " + ctunity.activePlayer(gameObject) + ", activeWrite: " + CTunity.activeWrite + ", newSession: " + ctunity.newSession + ", localP: " + ctunity.localPlayer(gameObject));
            //           Debug.Log("ctplayer: " + ctunity.ctplayer + ", paused: " + ctunity.gamePaused + ", replayActive: " + ctunity.replayActive + ", Player: " + ctunity.Player);
        }
        if (tkso != null && ctunity.activePlayer(gameObject) && !ctunity.localPlayer(collision.gameObject))
        {
            kso          = tkso;
            thisCollider = collision.collider;
            targetScale  = transform.localScale;
            stopWatch    = damageInterval;  // quick hit to start
            if (debug)
            {
                Debug.Log("HIT! thisCollider: " + thisCollider);
            }
        }
    }
Exemplo n.º 2
0
    //----------------------------------------------------------------------------------------------------------------
    // Update is called once per frame

    void Update()
    {
        if (ctunity == null || ctclient == null)
        {
            Debug.Log(name + ", oops no ctunity/ctlient!");
            return;        // async
        }
        if (!ctunity.activePlayer(gameObject))
        {
            return;
        }

        launchInterval = ctclient.getCustom("dt", launchInterval);

        stopWatch += Time.deltaTime;
        if (stopWatch >= launchInterval)
        {
            String missile = ctclient.getCustom("M", Missile);  // optional custom missile
            Ilaunch = ctclient.getCustom("N", Ilaunch);
            Nlaunch = ctclient.getCustom("Nmax", Nlaunch);
            //           Debug.Log(name + ": Nlaunch: " + Nlaunch+", launchInterval: "+launchInterval);

            if (Nlaunch != 0 && Ilaunch >= Nlaunch)
            {
                return;
            }

            ctunity.deployInventory(missile, CTunity.fullName(gameObject) + "/R-" + Ilaunch);
            Ilaunch++;
            ctclient.putCustom("N", Ilaunch);

            stopWatch = 0;
        }
    }
Exemplo n.º 3
0
 void OnCollisionExit(Collision collision)
 {
     if (debug)
     {
         Debug.Log(CTunity.fullName(gameObject) + ", END Collision with: " + collision.collider.name);
     }
     if (thisCollider == collision.collider)
     {
         thisCollider = null;
     }
 }
Exemplo n.º 4
0
 void OnTriggerExit(Collider collider)
 {
     if (debug)
     {
         Debug.Log(CTunity.fullName(gameObject) + ", END Trigger with: " + collider.name);
     }
     if (thisCollider == collider)
     {
         thisCollider = null;
     }
 }
Exemplo n.º 5
0
    //----------------------------------------------------------------------------------------------------------------
    void doCollision(Collider other)
    {
        if (debug)
        {
            Debug.Log(name + ": doCollision, showHP: " + showHP + ", kso: " + kso);
        }
        if (!showHP || kso == null)
        {
            return;                                                              // no game
        }
//        if (!showHP || kso == null || !ctunity.activePlayer(gameObject)) return;                                        // no game

        String myName    = CTunity.fullName(gameObject);
        String otherName = CTunity.fullName(other.gameObject);

        if (ctunity == null)
        {
            ctunity = GameObject.Find("CTunity").GetComponent <CTunity>();
        }
        if (other.gameObject == null || ctunity == null)
        {
            Debug.Log(name + ": OnTrigger null other object: " + other.name);
            return;
        }

        // compare hit levels to see who wins
        HP = ctclient.getCustom("HP", HP);
        int damage = (int)Math.Ceiling((float)kso.ATK / (float)AC);

        HP -= damage;
        if (HP < 0)
        {
            HP = 0;
        }
        ctclient.putCustom("HP", HP);
        if (HP <= 0)
        {
            if (killParent)  // can't destroyImmediate inside collision callback
            {
                ctunity.clearObject(gameObject.transform.parent.gameObject, false);
            }
            else
            {
                ctunity.clearObject(gameObject, false);
            }
        }
//        Debug.Log(myName + ", collide with: " + otherName+", damage: "+damage+", kso.ATK: "+kso.ATK+", AC: "+AC);

        if (scaleSize)
        {
            targetScale = initialScale * (0.1f + 0.9f * ((float)(HP) / (float)initialHP));
        }
    }
Exemplo n.º 6
0
    private Dictionary <String, String> kvdict = null; // local dictionary of custom key-values

    //----------------------------------------------------------------------------------------------------------------
    // Use this for initialization
    void Start()
    {
        rb      = GetComponent <Rigidbody>();
        ctunity = GameObject.Find("CTunity").GetComponent <CTunity>(); // reference CTunity script
        //       if (autoColor) setColor();          // set default color based on object name
        fullName = CTunity.fullName(gameObject);                       // get once in advance
        ctunity.CTregister(gameObject);                                // register with CTunity...
        trail = GetComponent <TrailRenderer>();                        // optional trail track
        // Debug.Log(name+": start ctunity: " + ctunity);

        if (LookAtMe)
        {
            GameObject.Find("Main Camera").GetComponent <maxCamera>().setTarget(transform);
        }
    }
Exemplo n.º 7
0
    //----------------------------------------------------------------------------------------------------------------
    // detect triggers

    void OnTriggerEnter(Collider collider)
    {
        if (debug)
        {
            Debug.Log(CTunity.fullName(gameObject) + ", Trigger with: " + collider.name);
        }

        if (!showHP)
        {
            return;
        }
        ScoreBoard tkso = collider.gameObject.GetComponent <ScoreBoard>();

        //        if(tkso != null) Debug.Log("new kso.ATK: " + tkso.ATK + ", thisCollider: " + thisCollider);

        if (tkso != null && ctunity.activePlayer(gameObject) && !ctunity.localPlayer(collider.gameObject))
        {
            kso          = tkso;
            thisCollider = collider;
            targetScale  = transform.localScale;
            stopWatch    = damageInterval;  // quick hit to start
        }
    }
Exemplo n.º 8
0
    /// <summary>
    /// Create a JSON serialized version of the player information.
    /// </summary>
    /// <param name="ctunityI">Source of the information to be serialized.</param>
    /// <returns>Serialized player information.</returns>
    private static string serialize_json(CTunity ctunityI)
    {
        CTworldJson world = new CTworldJson();

        world.player = ctunityI.Player;
        world.time   = ctunityI.ServerTime();
//		world.mode = ctunityI.replayText;
        world.objects = new List <CTobjectJson>();

        int objectCount = 0;

        foreach (GameObject ct in ctunityI.CTlist.Values)
        {
            if (!ctunityI.localPlayer(ct))
            {
                continue;                                                 // only save locally owned objects
            }
//			Debug.Log("CTserdes ct.name: " + fullName);

            if (ct == null)
            {
                continue;
            }
            CTclient ctp = ct.GetComponent <CTclient>();
            if (ctp == null)
            {
                continue;
            }
            String prefab = ctp.prefab;
            if (prefab.Equals("Ghost"))
            {
                continue;                                      // no save ghosts
            }
//			if (!ctunityI.replayActive && !ct.name.StartsWith(ctunityI.Player)) continue;  // only save locally owned objects
//			if (!ctunityI.doCTwrite(fullName)) continue;          // only save locally owned objects

            CTobjectJson obj = new CTobjectJson();
//			obj.id = ct.name;

            // strip leading world-name from embedded object name
            String fullName = CTunity.fullName(ct);
            if (fullName.StartsWith(world.player + "/"))
            {
                fullName = fullName.Remove(0, world.player.Length + 1);
            }
            //           Debug.Log("CTserdes obj.id: " + obj.id + ", world.player: " + world.player+", fullName: "+fullName);
            obj.id = fullName;

            obj.model = prefab;
//			obj.state = (ct.activeSelf ? true : false);
            // NOTE: limit floating point values to 4 decimal places
            obj.pos = new List <Double>();
            obj.pos.Add(LimitPrecision(ct.transform.localPosition.x, 4));                //  was .position
            obj.pos.Add(LimitPrecision(ct.transform.localPosition.y, 4));
            obj.pos.Add(LimitPrecision(ct.transform.localPosition.z, 4));
            obj.rot = new List <Double>();
            obj.rot.Add(LimitPrecision(ct.transform.localRotation.eulerAngles.x, 4));                // was .rotation
            obj.rot.Add(LimitPrecision(ct.transform.localRotation.eulerAngles.y, 4));
            obj.rot.Add(LimitPrecision(ct.transform.localRotation.eulerAngles.z, 4));
            obj.scale = new List <Double>();
            obj.scale.Add(LimitPrecision(ct.transform.localScale.x, 4));
            obj.scale.Add(LimitPrecision(ct.transform.localScale.y, 4));
            obj.scale.Add(LimitPrecision(ct.transform.localScale.z, 4));

            Renderer renderer = ct.transform.gameObject.GetComponent <Renderer>();
            if (renderer != null)
            {
//				Color mycolor = renderer.material.color;    // this NG for multi-part prefabs (e.g. biplane)
                Color mycolor = ctp.myColor;                                // NG?
                obj.color = new List <Double>();
                obj.color.Add(LimitPrecision(mycolor.r, 4));
                obj.color.Add(LimitPrecision(mycolor.g, 4));
                obj.color.Add(LimitPrecision(mycolor.b, 4));
                obj.color.Add(LimitPrecision(mycolor.a, 4));
            }

//			if (ctp.link != null && ctp.link.Length > 0) obj.link = ctp.link;
            if (ctp.custom != null && ctp.custom.Length > 0)
            {
                obj.custom = ctp.custom;
            }

            world.objects.Add(obj);
            objectCount++;
        }
//		Debug.Log("serialize: "+ world.player+", count: "+ objectCount);
        //		if (objectCount == 0) return null;  // notta.  (returning no-object string writes header-only)

        string jsonData = null;

        try
        {
            jsonData = JsonUtility.ToJson(world);
        }
        catch (Exception e)
        {
            UnityEngine.Debug.Log("Exception serializing JSON: " + e.Message);
            return(null);
        }

//		jsonData = jsonData.Replace("},", "},\n");     // for readability
        jsonData = jsonData.Replace("{\"id", "\n{\"id");             // for readability

        return(jsonData);
    }