Esempio n. 1
0
 public void DeleteUnit(BuildingUnit u)
 {
     for (int x = u.loc[0]; x <= u.loc[1]; x++)
     {
         roomUnits[x].SetActive(false);
     }
 }
Esempio n. 2
0
    public override bool isValidInteractor(Interactable interactor)
    {
        if (interactor == null)
        {
            return(false);
        }
        //check if team mate
        Unit         unitInteractor = interactor.GetComponent <Unit> ();
        BuildingUnit myUnit         = GetComponent <BuildingUnit> ();

        if (unitInteractor == null)
        {
            return(false);
        }
        if (myUnit == null)
        {
            return(false);
        }
        //VALIDATE ACCESS TYPE
        Debug.LogWarning("Unit " + unitInteractor.team + " is attacking the building " + myUnit.team + "!");
        if (unitInteractor.team == myUnit.team)
        {
            return(false);
        }

        return(true);
    }
    public void CmdSpawnObject(int spawnableIndex, Vector3 position, Quaternion rotation)
    {
        GameObject go = NetworkManager.singleton.spawnPrefabs[prefabBuildingIndex];

        //if (graphics == null) { Debug.LogError ("No graphics"); }
        go = Instantiate(go, position, rotation);

        BuildingUnit buildingUnit        = go.GetComponent <BuildingUnit> ();
        Vector3      navMeshObstacleSize = go.GetComponent <BoxCollider> ().size;

        AssignData(go, spawnableIndex, buildingUnit, navMeshObstacleSize);

        //DESTROY COMPONENTS NOT NEEDED
        Destroy(go.GetComponent <Rigidbody> ());
        Destroy(go.GetComponent <BuildingCreationTrigger> ());

        //SPAWNING AND AUTHORIZE BLDG
        NetworkServer.Spawn(go);
        bool ToF = go.GetComponent <NetworkIdentity> ().AssignClientAuthority(GetComponent <NetworkIdentity> ().connectionToClient);

        //SYNCING TO CLIENTS
        NetworkIdentity ni = go.GetComponent <NetworkIdentity> ();

        RpcAssignObject(ni, spawnableIndex);
    }
Esempio n. 4
0
    public BuildingUnit CreateBuildingUnit(string unit_name, int id, Vector3 pos)
    {
        GDSKit.building unit_gds = GDSKit.building.GetInstance(unit_name);

        GameObject building_unit_gameobj = ObjectPoolManager.Instance().GetObject(unit_gds.resource_name);

        building_unit_gameobj.transform.SetParent(cache_root_unit_node);

        BuildingUnit building_unit = building_unit_gameobj.GetComponent <BuildingUnit>();

        // 属性相关设置
        building_unit.unit_name    = unit_name;
        building_unit.unit_type    = UnitType.Building;
        building_unit.unit_id      = id;
        building_unit.resource_key = unit_gds.resource_name;
        building_unit.position     = pos;

        if (all_unit_list.ContainsKey(building_unit.unit_id))
        {
            Debug.LogError("相同名字的unit已经在管理器里了 id : " + building_unit.unit_id);
            return(null);
        }

        all_unit_list.Add(building_unit.unit_id, building_unit);
        buiding_unit_list.Add(building_unit.unit_id, building_unit);

        return(building_unit);
    }
        public ActionResult DeleteConfirmed(int id)
        {
            BuildingUnit buildingUnit = ctx.BuildingUnits.Find(id);

            ctx.BuildingUnits.Remove(buildingUnit);
            ctx.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 6
0
        private void Start()
        {
            Data = GameManager.current.buildingsManager.energyGenData;

            health       = Data.maxHealth;
            hasManager   = false;
            workersCount = 0;
            size         = Data.buildingSize;
        }
Esempio n. 7
0
    public void AddUnit(BuildingUnit u)
    {
        if (u.user_id == ParcelationManager.Instance.currentUserId)
        {
            int unitTypeIndex;

            if (System.Enum.TryParse(u.type, out LivingArrangement lv))
            {
                ParcelationManager.Instance.userUnitR.Clear();
                unitTypeIndex = (int)lv;
                for (int x = u.loc[0]; x <= u.loc[1]; x++)
                {
                    roomUnits[x].SetActive(true);
                    Renderer r = roomUnits[x].transform.GetChild(1).GetComponent <Renderer>();
                    r.material.SetColor("_Color", unitType[unitTypeIndex]._Color);    //TODO: Additional Hightlights
                    r.material.SetColor("_EmissionColor", unitType[unitTypeIndex]._EmissionColor);
                    //r.material.renderQueue = 3002;
                    ParcelationManager.Instance.userUnitR.Add(r);
                }
                ParcelationManager.Instance.UColor = unitType[unitTypeIndex]._EmissionColor;
                Vector4 v = unitType[unitTypeIndex]._EmissionColor;
                print("v set");
                ParcelationManager.Instance.uDelta = (Vector4.one - v) / 10f;
                print(ParcelationManager.Instance.uDelta);
            }
        }
        else
        {
            int unitTypeIndex;

            if (System.Enum.TryParse(u.type, out LivingArrangement lv))
            {
                unitTypeIndex = (int)lv;
            }
            else
            {
                if (System.Enum.TryParse(u.type, out SharedSpace ss))
                {
                    unitTypeIndex = 100 + (int)ss;
                }
                else
                {
                    unitTypeIndex = -1;
                }
            }
            for (int x = u.loc[0]; x <= u.loc[1]; x++)
            {
                roomUnits[x].SetActive(true);
                Renderer r = roomUnits[x].transform.GetChild(1).GetComponent <Renderer>();
                r.material.SetColor("_Color", unitType[unitTypeIndex]._Color);
                r.material.SetColor("_EmissionColor", unitType[unitTypeIndex]._EmissionColor);
                //r.material.renderQueue = 3002;
            }
        }

        RandomizeUnitSprite(u);
    }
Esempio n. 8
0
        private void Start()
        {
            print("CC Mono is working");
            Data = GameManager.current.buildingsManager.storageData;

            health       = Data.maxHealth;
            workersCount = 0;
            size         = Data.buildingSize;
        }
 public ActionResult Edit([Bind(Include = "Id,Area,UnitNo,MonthlyCharge,Payment,PaymentStatus,OwnerId,ResidentId")] BuildingUnit buildingUnit)
 {
     if (ModelState.IsValid)
     {
         ctx.Entry(buildingUnit).State = EntityState.Modified;
         ctx.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(buildingUnit));
 }
Esempio n. 10
0
        private void Start()
        {
            print("CC Mono is working");
            Data = GameManager.current.buildingsManager.commandCenterData;

            health       = Data.maxHealth;
            hasManager   = true;
            workersCount = 2;
            unitsHoused  = 3;
            size         = Data.buildingSize;
        }
        public ActionResult Create([Bind(Include = "Id,Area,UnitNo,MonthlyCharge,Payment,PaymentStatus,OwnerId,ResidentId")] BuildingUnit buildingUnit)
        {
            if (ModelState.IsValid)
            {
                ctx.BuildingUnits.Add(buildingUnit);
                ctx.SaveChanges();
                TempData["Message"]      = "اطلاعات واحد با موفقیت افزوده شد";
                TempData["MessageClass"] = "success";

                return(RedirectToAction("Index"));
            }

            return(View(buildingUnit));
        }
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BuildingUnit buildingUnit = ctx.BuildingUnits.Find(id);

            if (buildingUnit == null)
            {
                return(HttpNotFound());
            }
            return(View(buildingUnit));
        }
    //Cannot be accessed by enemy Builder
    //Can only be accessed by Builder
    public override bool isValidInteractor(Interactable interactor)
    {
        if (interactor == null)
        {
            return(false);
        }
        //check if team mate
        Unit         unitInteractor = interactor.GetComponent <Unit> ();
        BuildingUnit myUnit         = GetComponent <BuildingUnit> ();

        if (unitInteractor == null)
        {
            return(false);
        }
        if (myUnit == null)
        {
            return(false);
        }
        //VALIDATE ACCESS TYPE
//		Debug.LogWarning ("Unit " +unitInteractor.team+ " is attacking the building "+myUnit.team+"!");
        if (unitInteractor.team == myUnit.team)
        {
            Debug.LogWarning("Unit is supplying the building!");

            //is team mate
            if (unitInteractor.unitType != UnitType.Builder)
            {
                return(false);
            }
            accessType = BattleType.Sustaining;
        }
        else
        {
            Debug.LogWarning("Unit is attacking the building!");
            //is not team mate
            if (unitInteractor.unitType == UnitType.Builder)
            {
                return(false);
            }
            accessType = BattleType.Attacking;
        }

        return(true);
    }
Esempio n. 14
0
        public BLUnitBuilding CreateBuildingUnit(int unit_id, string gds_name, BLIntVector3 pos, int team_id)
        {
            GDSKit.building unit_gds = GDSKit.building.GetInstance(gds_name);

            BLUnitBuilding building_unit = new BLUnitBuilding();

            // 属性相关设置
            building_unit.gds_name        = gds_name;
            building_unit.unit_type       = UnitType.Building;
            building_unit.unit_id         = unit_id;
            building_unit.vision          = unit_gds.vision;
            building_unit.hp              = unit_gds.building_hp;
            building_unit.max_hp          = unit_gds.building_hp;
            building_unit.can_revive_hero = unit_gds.can_revive_hero;

            building_unit.position = pos;

            building_unit.team_id = team_id;


            if (all_unit_list.ContainsKey(building_unit.unit_id))
            {
                Debug.LogError("相同名字的unit已经在管理器里了 id : " + building_unit.unit_id);
                return(null);
            }

            all_unit_list.Add(building_unit.unit_id, building_unit);
            buiding_unit_list.Add(building_unit.unit_id, building_unit);

            building_unit.OnInit();

            // 表现层
            BuildingUnit unit_renderer = UnitManager.Instance().CreateBuildingUnit(building_unit.gds_name, building_unit.unit_id, building_unit.position.Vector3Value());

            unit_renderer.attack_vision = building_unit.vision * 0.001f;
            unit_renderer.team_id       = team_id;

            unit_renderer.OnInit();

            return(building_unit);
        }
    public void RpcAssignObject(NetworkIdentity id, int spawnableIndex)
    {
        //	if(!isLocalPlayer)return;

        //Debug.Log(id.netId.Value);
        GameObject spawnHolder     = id.gameObject;
        GameObject graphics        = buildingGroups.buildings[spawnableIndex].graphics;
        Vector3    grapihicsOffset = new Vector3(0, graphics.transform.localScale.y / 2, 0);

        graphics = Instantiate(graphics, spawnHolder.transform.position + grapihicsOffset, spawnHolder.transform.rotation, spawnHolder.transform);
        graphics.GetComponent <GraphicsHolder> ().colorize(LobbyManager.singleton.GetComponent <LobbyManager> ().gameColors.gameColorList() [PO.colorIndex]);
        BuildingUnit buildingUnit        = spawnHolder.GetComponent <BuildingUnit> ();
        Vector3      navMeshObstacleSize = spawnHolder.GetComponent <BoxCollider> ().size;

        AssignData(spawnHolder, spawnableIndex, buildingUnit, navMeshObstacleSize);

        if (spawnHolder.transform.childCount <= 0)
        {
            Debug.LogError("No graphics");
        }
        NavMeshObstacle navMeshObstacle = spawnHolder.AddComponent(typeof(NavMeshObstacle)) as NavMeshObstacle;

        navMeshObstacleSize.x  -= obstacleSizeCut;
        navMeshObstacleSize.y  -= obstacleSizeCut;
        navMeshObstacleSize.z  += obstacleHeightAdd;
        navMeshObstacle.size    = navMeshObstacleSize;
        navMeshObstacle.carving = true;
        spawnHolder.name        = PO.team + " - bldg - " + id.netId;

        spawnHolder.GetComponent <BuildingStats> ().netPlayer = PO;
        GraphicsHolder graphicsHolder = spawnHolder.GetComponentInChildren <GraphicsHolder> ();

        buildingUnit.team = PO.team;
        if (graphicsHolder != null)
        {
            graphicsHolder.colorize(LobbyManager.singleton.GetComponent <LobbyManager> ().gameColors.gameColorList() [PO.colorIndex]);
        }
        PO.myBuildings.Add(spawnHolder);
    }
    public void AssignData(GameObject spawnHolder, int spawnableIndex, BuildingUnit buildingUnit, Vector3 navMeshObstacleSize)
    {
        //Assign data

        buildingUnit.team         = PO.team;
        buildingUnit.buildingType = buildingGroups.buildings[spawnableIndex].type;

        BuildingInteractable buildingInteractable = null;

        switch (buildingGroups.buildings[spawnableIndex].type)
        {
        case BuildingType.Barracks:
            buildingInteractable = spawnHolder.AddComponent <BuildingInteractable> ();
            break;

        case BuildingType.TownCenter:
            buildingInteractable = spawnHolder.AddComponent <BuildingInteractable> ();
            break;

        case BuildingType.Tower:
            buildingInteractable = spawnHolder.AddComponent <BuildingInteractable> ();
            break;

        case BuildingType.SupplyChain:
            buildingInteractable = spawnHolder.AddComponent <SupplyChainInteractable> ();
            break;
        }
        if (navMeshObstacleSize.x > navMeshObstacleSize.z)
        {
            buildingInteractable.influenceRadius = navMeshObstacleSize.x + 1;
        }
        else
        {
            buildingInteractable.influenceRadius = navMeshObstacleSize.z + 1;
        }
        //end of assignments
    }
 public async Task OnUpdate(GuoGuoCommunityContext db, BuildingUnit buildingUnit, CancellationToken token = default)//触发事件的方法
        
 {
     await Task.Run(() => BuildingUnitEvent(db, buildingUnit, token));
 }
    IEnumerator GenerateSpeechBubble()
    {
        if (ShowMessages && messageTopics != null && messageTopics.Count != 0)
        {
            _messageLock = true;
            TopicCursor  = (TopicCursor + 1) % messageTopics.Count;
            int colorSeed    = Random.Range(0, bubbleColors.Length);
            int messageIndex = 0;
            int maxCount     = 10;
            //TODO: set message limit?
            // Random with limit for units only
            List <double> rList = (currentBuildingState.Keys.ToList <double>()).OrderBy(a => System.Guid.NewGuid()).ToList();;
            foreach (double i in rList)
            {
                if (messageIndex < messageTopics[TopicCursor].messages.Count)
                {
                    BuildingUnit  u = currentBuildingState[i];
                    System.Random n = new System.Random();
                    int           j = Random.Range(u.loc[0], u.loc[1] + 1);

                    Vector3 pos    = floors[u.floor].roomUnits[j].transform.position;
                    Vector3 camPos = cam.WorldToScreenPoint(floors[u.floor].roomUnits[j].transform.position);
                    //Debug.LogError("ScreenPos:");
                    //Debug.LogError(camPos);

                    if (camPos.z > 0)
                    {
                        //TODO: update position in local script
                        GameObject m = Instantiate(messageBubble2D, cam.WorldToScreenPoint(floors[u.floor].roomUnits[j].transform.position), messageBubble2D.transform.rotation, messageOverlay);
                        m.transform.GetChild(0).GetComponent <UnityEngine.UI.Text>().text = messageTopics[TopicCursor].messages[messageIndex].message;
                        int c = colorSeed++ % bubbleColors.Length;
                        m.GetComponent <UnityEngine.UI.Image>().color = bubbleColors[c];//TopicCursor % bubbleColors.Length];
                        m.GetComponent <MessageBubble2D>().trackedPos = pos;
                        //GameObject m = Instantiate(messageBubble2D);
                        //m.transform.SetParent(messageOverlay);
                        //m.GetComponent<RectTransform>().anchoredPosition = screenPos;
                    }

                    //--Scene spawn mesh method
                    //GameObject o;
                    //if (j < 8)
                    //{
                    //    o = Instantiate(bubbleLeftPrefab);
                    //    o.transform.SetParent(floors[u.floor].roomUnits[j].transform);
                    //    o.transform.localPosition = new Vector3(-0.112f, 0.062f, -0.111f);
                    //    if (j == 2 || j == 3 || j == 7)
                    //        o.transform.localPosition = new Vector3(-0.112f, 0.062f, -0.189f);
                    //}
                    //else
                    //{
                    //    //print(string.Format("x={0} y={1}", j, i));
                    //    o = Instantiate(bubbleRightPrefab);
                    //    o.transform.SetParent(floors[u.floor].roomUnits[j].transform);
                    //    o.transform.localPosition = new Vector3(0.112f, 0.062f, -0.111f);
                    //    if (j == 8 || j == 12 || j == 13)
                    //        o.transform.localPosition = new Vector3(0.112f, 0.062f, -0.189f);
                    //}
                    //o.transform.localRotation = Quaternion.Euler(-90, 0, 180);
                    //o.GetComponent<Bubble>().SetText(messageTopics[TopicCursor].messages[messageIndex].message);
                    //print(string.Format("Message spawned at [{0},{1}]", i, j));
                    ////print(string.Format("message topic: {0}: {1}. {2}", TopicCursor, messageIndex, messageTopics[TopicCursor].messages[messageIndex].message));
                    //int c = colorSeed++ % bubbleColors.Length;
                    //o.GetComponent<Renderer>().material.SetColor("_Color", bubbleColors[c]);
                    //o.GetComponent<Renderer>().material.SetColor("_EmissionColor", bubbleColors[c]);

                    messageIndex++;
                    maxCount--;
                    if (maxCount <= 0)
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
            }

            // Random with limit for entire building
            //foreach (int i in Enumerable.Range(0, floorCount).OrderBy(x => r.Next()))
            //{
            //    if (messageIndex < messageTopics[TopicCursor].messages.Count)
            //    {
            //        System.Random n = new System.Random();
            //        int j = Random.Range(0, 16);
            //        GameObject o;
            //        if (j < 8)
            //        {
            //            o = Instantiate(bubbleLeftPrefab);
            //            o.transform.SetParent(floors[i].roomUnits[j].transform);
            //            o.transform.localPosition = new Vector3(-0.112f, 0.062f, -0.111f);
            //            if (j == 2 || j == 3 || j == 7)
            //                o.transform.localPosition = new Vector3(-0.112f, 0.062f, -0.189f);
            //        }
            //        else
            //        {
            //            //print(string.Format("x={0} y={1}", j, i));
            //            o = Instantiate(bubbleRightPrefab);
            //            o.transform.SetParent(floors[i].roomUnits[j].transform);
            //            o.transform.localPosition = new Vector3(0.112f, 0.062f, -0.111f);
            //            if (j == 8 || j == 12 || j == 13)
            //                o.transform.localPosition = new Vector3(0.112f, 0.062f, -0.189f);
            //        }
            //        o.transform.localRotation = Quaternion.Euler(-90, 0, 180);
            //        o.GetComponent<Bubble>().SetText(messageTopics[TopicCursor].messages[messageIndex].message);
            //        print(string.Format("Message spawned at [{0},{1}]", i, j));
            //        //print(string.Format("message topic: {0}: {1}. {2}", TopicCursor, messageIndex, messageTopics[TopicCursor].messages[messageIndex].message));
            //        int c = colorSeed++ % bubbleColors.Length;
            //        o.GetComponent<Renderer>().material.SetColor("_Color", bubbleColors[c]);
            //        o.GetComponent<Renderer>().material.SetColor("_EmissionColor", bubbleColors[c]);
            //        messageIndex++;
            //    }
            //    else break;
            //}

            // Binomial Randomization
            //for (int i = 0; i < floorCount; i++)
            //{
            //    //List<string> data = new List<string>();
            //    for (int j = 0; j < 16; j++)
            //    {
            //        if (Random.value < bubbleSpanProb)
            //        {
            //            GameObject o;
            //            if (j < 8)
            //            {
            //                o = Instantiate(bubbleLeftPrefab);
            //                o.transform.SetParent(floors[i].roomUnits[j].transform);
            //                o.transform.localPosition = new Vector3(-0.112f, 0.062f, -0.111f);
            //                if (j == 2 || j == 3 || j == 7)
            //                    o.transform.localPosition = new Vector3(-0.112f, 0.062f, -0.189f);
            //            }
            //            else
            //            {
            //                //print(string.Format("x={0} y={1}", j, i));
            //                o = Instantiate(bubbleRightPrefab);
            //                o.transform.SetParent(floors[i].roomUnits[j].transform);
            //                o.transform.localPosition = new Vector3(0.112f, 0.062f, -0.111f);
            //                if (j == 8 || j == 12 || j == 13)
            //                    o.transform.localPosition = new Vector3(0.112f, 0.062f, -0.189f);
            //            }
            //            o.transform.localRotation = Quaternion.Euler(-90, 0, 180);
            //            o.GetComponent<Bubble>().SetText("Bob ran down the hill to catch snails.");
            //            int c = colorSeed++ % bubbleColors.Length;
            //            o.GetComponent<Renderer>().material.SetColor("_Color", bubbleColors[c]);
            //            o.GetComponent<Renderer>().material.SetColor("_EmissionColor", bubbleColors[c]);
            //        }
            //    }
            //}
            _messageLock = false;
        }
        yield return(new WaitForSeconds(generationTime));

        StartCoroutine(GenerateSpeechBubble());
    }
Esempio n. 19
0
    public void RandomizeUnitSprite(BuildingUnit u)
    {
        int unitTypeIndex;

        System.Random r = new System.Random();
        if (System.Enum.TryParse(u.type, out LivingArrangement lv))
        {
            //print(lv.ToString());
            unitTypeIndex = (int)lv;
            int   n  = 0;
            int[] sI = unitType[unitTypeIndex].spriteIndices;

            //Debug.LogError(string.Format("Fetching from [{0},{1}], count: {2}", u.loc[0], u.loc[1], u.loc[1] + 1 - u.loc[0]));
            int study = u.user_input.requiredRooms[RequiredRooms.Study.ToString()];
            foreach (int i in Enumerable.Range(u.loc[0], u.loc[1] + 1 - u.loc[0]).OrderBy(x => r.Next()))
            {
                //output study on facade
                if (study > 0)
                {
                    if ((i > 1 && i < 4) || (i > 6 && i < 9) || (i > 11 && i < 14))
                    {
                    }
                    else
                    {
                        sprites[i].SetActive(true);
                        SpriteRenderer s = sprites[i].GetComponent <SpriteRenderer>();

                        s.sprite = ParcelationManager.sprites[9];
                        s.color  = Color.black;
                        //s.material.renderQueue = 3002;
                        study--;
                        continue;
                    }
                }
                //output cohabitation otherwise
                if (n < sI.Length)
                {
                    //Debug.LogWarning("row "+u.floor+" col "+ i + " fetching: " + sI[n].ToString());
                    sprites[i].SetActive(true);
                    SpriteRenderer s = sprites[i].GetComponent <SpriteRenderer>();

                    s.sprite = ParcelationManager.sprites[sI[n]];
                    s.color  = Color.black;
                    //s.material.renderQueue = 3002;
                    n++;
                }
                else
                {
                    //Debug.LogError("TURNING OFF row " + u.location[0] + " col " + col);
                    sprites[i].SetActive(false);
                }
            }
        }
        else
        {
            if (System.Enum.TryParse(u.type, out SharedSpace ss))
            {
                unitTypeIndex = 100 + (int)ss;
                int[] sI = unitType[unitTypeIndex].spriteIndices;

                int j = u.loc[0] + (u.loc[1] - u.loc[0]) / 2;
                if ((j == 2) || (j == 7) || (j == 12))
                {
                    j--;
                }
                else if ((j == 3) || (j == 8) || (j == 13))
                {
                    j++;
                }

                foreach (int i in Enumerable.Range(u.loc[0], u.loc[1] + 1 - u.loc[0]).OrderBy(x => r.Next()))
                {
                    if (i == j)
                    {
                        sprites[i].SetActive(true);
                        SpriteRenderer s = sprites[i].GetComponent <SpriteRenderer>();
                        s.sprite = ParcelationManager.sprites[sI[0]];
                        s.color  = Color.black;
                        //s.material.renderQueue = 3002;
                    }
                    else
                    {
                        //Debug.LogError("TURNING OFF row " + u.location[0] + " col " + col);
                        sprites[i].SetActive(false);
                    }
                }
            }
            else
            {
                unitTypeIndex = -1;
            }
        }
    }