Пример #1
0
        public ShipConstruct CreateShipConstruct(string part_name, string flag_url)
        {
            var kit_part = CreatePart(part_name, flag_url, true);

            return(kit_part
                ? PartMaker.CreatePartConstruct(kit_part, "DIY Kit: " + Name, "")
                : null);
        }
Пример #2
0
        public bool Create()
        {
            IList <ElementId>       idList             = new List <ElementId>();
            ICollection <ElementId> elementIdsToDivide = new List <ElementId>();

            idList.Add(Floor.Id);
            if (PartUtils.AreElementsValidForCreateParts(PublicVariables.Doc, idList))
            {
                using (Transaction tr = new Transaction(PublicVariables.Doc, "CreatePart"))
                {
                    tr.Start();
                    try
                    {
                        PartUtils.CreateParts(PublicVariables.Doc, idList);
                        tr.Commit();
                    }
                    catch
                    {
                        tr.RollBack();
                    }
                    elementIdsToDivide = PartUtils.GetAssociatedParts(PublicVariables.Doc
                                                                      , Floor.Id, true, true);
                }
            }

            ICollection <ElementId> intersectingReferenceIds = new List <ElementId>();
            var curveList = (from Curve elem in BoundingSquare
                             select elem).ToList();

            using (Transaction tr = new Transaction(PublicVariables.Doc, "DivideParts"))
            {
                tr.Start();
                try
                {
                    SketchPlane sp = SketchPlane.Create(PublicVariables.Doc,
                                                        Plane.CreateByNormalAndOrigin(new XYZ(0, 0, 1), BoundingSquare[0].GetEndPoint(0)));

                    PartMaker maker = PartUtils.DivideParts(PublicVariables.Doc,
                                                            elementIdsToDivide, intersectingReferenceIds, curveList, sp.Id);

                    Parameter partVisInView = PublicVariables.Doc.ActiveView.get_Parameter(BuiltInParameter.VIEW_PARTS_VISIBILITY);
                    partVisInView.Set(0);
                    tr.Commit();
                }
                catch
                {
                    tr.RollBack();
                }
            }

            return(true);
        }
Пример #3
0
        public Part CreatePart(string part_name, string flag_url, bool set_host)
        {
            var kit_part = PartMaker.CreatePart(part_name, flag_url);
            //add the kit to construction kit module
            var kit_module = kit_part.FindModuleImplementing <DeployableKitContainer>();

            if (kit_module == null)
            {
                Utils.Message("{0} has no DeployableKitContainer-dervied MODULE", part_name);
                UnityEngine.Object.Destroy(kit_part);
                return(null);
            }
            kit_module.StoreKit(this);
            if (set_host)
            {
                Host = kit_module;
            }
            return(kit_part);
        }
Пример #4
0
 private void Awake()
 {
     lastGameTime = ObjectsLoader.gameTime;
     lastAction   = null;
     myLaser      = null;
     hits         = -1;
     energy       = -1;
     pM           = null;
     creepEnergy  = transform.GetChild(0).gameObject;
     creepBadge   = transform.GetChild(1).gameObject;
     creepTough   = transform.GetChild(3).gameObject;
     moving       = false;
     lastPosition = new Vector2Int(-100, -100);
     if (fadeoutSprites == null || fadeoutSprites.Count == 0)
     {
         fadeoutSprites = new List <SpriteRenderer>();
         if (gameObject.GetComponent <SpriteRenderer>() != null)
         {
             fadeoutSprites.Add(gameObject.GetComponent <SpriteRenderer>());
         }
         fadeoutSprites.AddRange(gameObject.GetComponentsInChildren <SpriteRenderer>());
     }
 }
Пример #5
0
    public void CreepData(JSONObject dataIn)
    {
        if (dataIn == null)
        {
            DeleteCreep(); return;
        }
        _id = dataIn["_id"] != null ? dataIn["_id"].ToString().Replace("\"", "") : _id;
        //user = dataIn["user"] != null ? dataIn["user"].ToString().Replace("\"", "") : _id;
        int x = dataIn["x"] != null?Int32.Parse(dataIn["x"].ToString()) : lastPosition.x;

        int y = dataIn["y"] != null?Int32.Parse(dataIn["y"].ToString()) : lastPosition.y;

        if (lastPosition == new Vector2Int(-100, -100))
        {
            lastPosition = new Vector2Int(x, -y + 50);
        }
        if (lastPosition.x != x || lastPosition.y != y)
        {
            moving        = true;
            newPosition   = lastPosition.y != y ? new Vector2Int(x, -y + 50) : new Vector2Int(x, y);
            moveStartTime = Time.time;
            int newDir = new Dir(lastPosition, newPosition).dir;
            StartCoroutine(TurnTo(newDir));
            v3lastPosition = new Vector3(lastPosition.x * 0.16f + 0.08f, lastPosition.y * 0.16f + 0.08f, -1f);
            v3newPosition  = new Vector3(newPosition.x * 0.16f + 0.08f, newPosition.y * 0.16f + 0.08f, -1f);
            moveDistance   = Vector3.Distance(v3lastPosition, v3newPosition);
        }
        if (dataIn["energy"] != null)
        {
            int e = Int32.Parse(dataIn["energy"].ToString());
            if ((energy == -1 && e == 0) || e != energy)
            {
                if (energyCapacity == 0 && dataIn["energyCapacity"])
                {
                    energyCapacity = Int32.Parse(dataIn["energyCapacity"].ToString());
                }
                SetEnergy(e);
            }
        }
        if (dataIn["name"] != null)
        {
            name = dataIn["name"].ToString().Replace("\"", "");
        }
        if (dataIn["hits"] != null)
        {
            hits = Int32.Parse(dataIn["hits"].ToString());
        }
        if (dataIn.HasField("user"))
        {
            dataIn.GetField(ref user, "user");
        }
        if ((user == "2" || user == "3") && creepTough != null)
        {
            Destroy(creepTough);
            creepTough = null;
        }
        if (dataIn.HasField("body"))
        {
            if (creepBody.parts.Length <= 0)
            {
                creepBody = new CreepBody(dataIn["body"]);
            }
            if (creepBody.parts.Length > 0)
            {
                maxHits = creepBody.parts.Length * 100;
            }
            if (creepParts == null)
            {
                creepParts = transform.GetChild(2).gameObject;
            }

            //creepParts.TryGetComponent<PartMaker>(out pM);
            if (pM == null && !(user == "2" || user == "3"))
            {
                pM = creepParts.AddComponent <PartMaker>();
                pM.CreateParts(creepBody, creepParts);
            }
        }
        if (dataIn.HasField("actionLog"))
        {
            //"attacked":null,"healed":null,"attack":null,"rangedAttack":null,"rangedMassAttack":null,"rangedHeal":null,"harvest":{"x":33,"y":14},"heal":null,"repair":null,"build":null,"say":null,"upgradeController":null,"reserveController":null
            var actionLog = dataIn.GetField("actionLog");
            foreach (var action in actionLog.keys)
            {
                if (actionLog[action].type == JSONObject.Type.NULL)
                {
                    if (lastAction == action)
                    {
                        lastAction = null;
                    }
                    continue;
                }
                string actionType = Convert.ToString(action);
                int    tarX       = 0;
                int    tarY       = 0;
                if (actionLog[action].HasField("x"))
                {
                    actionLog[action].GetField(ref tarX, "x");
                }
                if (actionLog[action].HasField("y"))
                {
                    actionLog[action].GetField(ref tarY, "y");
                }
                tarY = 50 - tarY;
                Vector2Int targetPos = new Vector2Int(tarX, tarY);
                lastTarget = targetPos;
                if (actionType == "upgradeController" || actionType == "rangedHeal" || actionType == "rangedAttack" || actionType == "repair" || actionType == "build")
                {
                    lastAction = actionType;
                    ShootTarget(targetPos, actionType);
                }
                if (actionType == "attack" || actionType == "harvest" || actionType == "heal" || actionType == "reserveController")
                {
                    lastAction = actionType;
                    Dir newDir = new Dir(lastPosition, targetPos);
                    //StartCoroutine(TurnTo(newDir.dir));
                    //if (!moving)
                    //{
                    //Debug.Log("Starting Bumpto");
                    StartCoroutine(StartBump(newDir));
                    //}
                }
            }
        }
    }