/// <summary>
    /// Sells the placeable and returns some gold to the player.
    /// </summary>
    public void SellPlaceable(Placeable placeableToSell)
    {
        placeableToSell.Sell();
        Player.Instance.Gold += GetSellPrice(placeableToSell);

        // Return to the pool
        PlaceablePool.Instance.ReclaimObject(placeableToSell);
    }
示例#2
0
 internal void AddMovingObject(Placeable p)
 {
     movingObjects[p] = movingObjectInsterPtr++;
     if (movingObjectInsterPtr >= movingObjectMaxPtr)
     {
         movingObjectInsterPtr = 0;
     }
 }
示例#3
0
    private void Start()
    {
        placeable = new Placeable("demo");

        placeable.AddTag(PlaceableTag.tagBlueSkillToken);
        //placeable.AddTag(PlaceableTag.tagGreenSkillToken);
        //Debug.Log("done");
    }
示例#4
0
 private void attemptConnection(int ourPointIndex, Placeable otherPlaceable, int theirPointIndex)
 {
     Debug.Log("Attempting connection");
     if (canConnectAtPoint(ourPointIndex) && otherPlaceable.canConnectAtPoint(theirPointIndex))
     {
         makeConnection(ourPointIndex, otherPlaceable, theirPointIndex);
     }
 }
示例#5
0
 private void RemoveElement()
 {
     if (placeable != null)
     {
         manager.ReturnPlaceable(placeable);
         Destroy(placeable.gameObject);
     }
     placeable = null;
 }
示例#6
0
    private void Update()
    {
        var        cameraRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hitInfo;

        if (placeableInstance != null)
        {
            if (Input.GetKeyDown(KeyCode.R))
            {
                placeableInstance.transform.Rotate(new Vector3(0, 90, 0), Space.World);
            }

            if (Input.GetKeyDown(KeyCode.Escape))
            {
                ClearPlaceable();
                return;
            }

            if (CanPlace())
            {
                placeableInstance.GetComponent <Selectable>().ChangeColor(Color.green);
            }
            else
            {
                placeableInstance.GetComponent <Selectable>().ChangeColor(Color.red);
            }

            var selectionManager = SelectionManager.GetInstance();
            if (Physics.Raycast(cameraRay, out hitInfo, float.MaxValue, LayerMask.GetMask("Ground")))
            {
                placeableInstance.transform.position = hitInfo.point;
                if (CanPlace() && Input.GetMouseButtonUp(0) && !EventSystem.current.IsPointerOverGameObject())
                {
                    if (ResourceManager.GetInstance().OffsetAll(-placeableInstance.GetWoodCost(), -placeableInstance.GetStoneCost(), -placeableInstance.GetMetalCost(), 0))
                    {
                        var buildSite = BuildSite.Instantiate(placeableInstance).GetComponent <Assignable>();
                        foreach (var worker in selectionManager.GetSelected().Where(s => s.GetComponent <Worker>() != null).Select(s => s.GetComponent <Worker>()).OrderBy(s => s.IsAssigned()))
                        {
                            if (!buildSite.AddWorker(worker))
                            {
                                break;
                            }
                        }
                        placeableInstance.GetComponent <Selectable>().ChangeColor(Color.clear);
                        placeableInstance = null;
                        selectionManager.DeselectAll();
                        selectionManager.Enable();
                    }
                }
                else if (Input.GetMouseButtonUp(1))
                {
                    ClearPlaceable();
                    return;
                }
            }
        }
    }
示例#7
0
 public void ClearPlaceable()
 {
     if (placeableInstance != null)
     {
         placeableInstance.Remove();
         placeableInstance = null;
         SelectionManager.GetInstance().Enable();
     }
 }
示例#8
0
        private void DuplicatePlaceable_Click(object sender, RoutedEventArgs e)
        {
            TileManagerViewModel vm        = DataContext as TileManagerViewModel;
            Placeable            duplicate = vm.SelectedPlaceable.Duplicate(true);

            duplicate.Name += string.Format(" ({0})", vm.SelectedCollection.PlaceableFile.Data.Count(x => x.Name == duplicate.Name));
            vm.SelectedCollection.PlaceableFile.Data.Add(duplicate);
            vm.SelectedPlaceableIndex = vm.SelectedCollection.PlaceableFile.Data.Count - 1;
        }
示例#9
0
    private void makeConnection(int ourPointIndex, Placeable otherPlaceable, int theirPointIndex)
    {
        var connectionSuccess = otherPlaceable.receiveConnection(theirPointIndex, this, ourPointIndex);

        if (connectionSuccess)
        {
            receiveConnection(ourPointIndex, otherPlaceable, theirPointIndex);
        }
    }
示例#10
0
 private void MarkByCP(Placeable p, int zShift, Content content)
 {
     Mark2x2(p, zShift, content, new Vector2Int(1, 1));
     Mark2x2(p, zShift, content, new Vector2Int(3, 1));
     Mark2x2(p, zShift, content, new Vector2Int(5, 1));
     Mark2x2(p, zShift, content, new Vector2Int(1, 3));
     Mark2x2(p, zShift, content, new Vector2Int(3, 3));
     Mark2x2(p, zShift, content, new Vector2Int(5, 3));
 }
示例#11
0
 public void CmdInputShot(GameObject shotPlaceable)
 {
     this.shotPlaceable = shotPlaceable.GetComponent <Placeable>();
     if (isServer)
     {
         Debug.Log("Coucou shot commanded");
         Debug.Log(shotPlaceable);
     }
 }
示例#12
0
    /// <summary>
    /// Spawn the object and parse and apply any additional parameters
    /// </summary>
    /// <param name="obj">The object string along with parameters</param>
    private void PlaceObject(string obj, Vector3 position, Transform parent)
    {
        string[] obj_id      = obj.Split(ID_SEPERATOR);
        string[] color       = obj_id[0].Split(COL_SEPERATOR);
        string[] orientation = color[0].Split(ROT_SEPERATOR);
        string   tile        = orientation[0];

        if (!placeablesMap.ContainsKey(tile))
        {
            UserErrorInfo.ErrorWriter.AddMessage($"Invalid symbol '{tile}' at position '{position}'");
            return;
        }

        Placeable p = placeablesMap[tile];

        if (p.prefabs.Length == 0)
        {
            UserErrorInfo.ErrorWriter.AddMessage($"No prefabs assigned for object '{tile}'");
            return;
        }

        GameObject prefab   = p.prefabs[Random.Range(0, p.prefabs.Length)];
        GameObject instance = Instantiate(prefab, position, Quaternion.identity, parent);

        if (tile == "cb")
        {
            if (color.Length < 2)
            {
                UserErrorInfo.ErrorWriter.AddMessage($"The ColorButton '{obj_id}' requires a color parameter");
            }
            instance.GetComponent <ColorButton>().SetColor(Utils.colorFromHexString(color[1]));
        }

        if (orientation.Length > 1)
        {
            RotateObject(instance, orientation[1]);
        }

        if (obj_id.Length > 1)
        {
            string id = obj_id[1];
            if (p.group == EntityGroup.Agents)
            {
                AssignAgentID(instance, id, obj, position);
            }
            else
            {
                instance.name = id;
            }
        }
        else if (ObjectIDRequired(p.group))
        {
            UserErrorInfo.ErrorWriter.AddWorldMessage($"No ID specified for '{tile}', required for {p.group}.", obj, position);
            return;
        }
    }
示例#13
0
文件: Main.cs 项目: csheldondante/MGP
    private void CreateTerrain()
    {
        DataEntity terrain = new DataEntity();

        _entities.Add(terrain);
        Placeable placeable       = new Placeable(terrain);
        Tilemap2D terrainViewable = new Tilemap2D(terrain);

        _viewManager.AddViewable(terrainViewable);
    }
示例#14
0
    public void CmdMoveTo(NetworkInstanceId toGo)
    {
        Placeable potential = NetworkServer.FindLocalObject(toGo).GetComponent <Placeable>();

        if (gameManager.PlayingPlaceable.joueur == this)//on update que si c'est à son tour de jouer, on fait les autres vérifs dans la Gamemanager
        {
            placeToGo = potential.position;
            Debug.Log(placeToGo);
        }
    }
示例#15
0
 protected virtual void OnPlaceablePainted(Placeable placeable)
 {
     if (PlaceablePainted != null)
     {
         PlaceablePainted(this, new PlaceablePaintedEventArgs()
         {
             NewPlaceable = placeable
         });
     }
 }
示例#16
0
    private void setTextBasedOnValue(Placeable building, ResourceType type, bool produce = true)
    {
        float?value = produce? getProduceValue(building.gameObject, type) : getConsumeValue(building.gameObject, type);
        var   text  = produce ? produceDictionary[type] : consumeDictionary[type];

        Debug.Log(text.gameObject.name);
        Debug.Log(value);

        setOrHideText(text, value, type);
    }
示例#17
0
 /// <summary>
 /// Performs initialization related to the placing component.
 /// </summary>
 private void InitPlaceableComponent()
 {
     placeableComponent = gameObject.GetComponentInChildren <Placeable>(true);
     if (placeableComponent != null)
     {
         placeableComponent.StartedPlacing += OnStartedPlacingMagnet;
         placeableComponent.StoppedPlacing += OnStoppedPlacingMagnet;
         placeableComponent.StartPlacing(false);
     }
 }
示例#18
0
        private void CheckValidPlaceable(string input, string rest = "")
        {
            var cs = NCS(input);

            L20n.FTL.AST.INode result;
            Assert.IsTrue(Placeable.PeekAndParse(cs, out result));
            Assert.IsNotNull(result);
            Assert.AreEqual(rest, cs.ReadUntilEnd());
            Assert.AreEqual(typeof(L20n.FTL.AST.Placeable), result.GetType());
        }
    public override GameObject cloneObj(GameObject model, Placeable data, RaycastHit hit)
    {
        GameObject newFlower = GameObject.Instantiate(model, posClamp(hit), Quaternion.identity, hit.transform);//make a copy

        //newFlower.name = x + " " + y;//placement stuff
        newFlower.transform.LookAt(transform.position);
        int yRot = (int)((mainCamera.transform.parent.eulerAngles.y + 225) / 90);

        newFlower.transform.eulerAngles = new Vector3(0, yRot * 90, 0);
        //        newFlower.transform.Rotate(new Vector3(0, 90, 0));
        newFlower.SetActive(true);
        newFlower.transform.localScale = Vector3.one;

        benchController currentFlowerObj = newFlower.GetComponent <benchController>();

        int[]   flowerGridLoc            = WorldManager.instance.worldPointToFlowerGrid(hit.point);//find what grid the point is in
        float   chunkOverFlower          = (float)WorldManager.instance.chunkWidth / WorldManager.instance.FlowerWidthPerChunk;
        Vector3 flowerCellCenterPosition = VectorUtilities.VectorAdd((VectorUtilities.VectorFloor(hit.point * chunkOverFlower) / chunkOverFlower), (chunkOverFlower * .5f));
        int     x2 = flowerGridLoc[0];
        int     y2 = flowerGridLoc[1];

        WorldManager.instance.placableGrid[x2, y2] = currentFlowerObj;//move the flower data over
        Vector3 distanceFromCenter = hit.point - flowerCellCenterPosition;

        if (yRot % 2 == 0)
        {
            if (distanceFromCenter.x > 0)
            {
                x2++;
            }
            else
            {
                x2--;
            }
        }
        else
        {
            if (distanceFromCenter.z > 0)
            {
                y2++;
            }
            else
            {
                y2--;
            }
        }
        x2 = WorldManager.instance.trueX(x2);
        y2 = WorldManager.instance.trueX(y2);
        WorldManager.instance.removeFromFlowerList(x2, y2);
        WorldManager.instance.placableGrid[x2, y2] = currentFlowerObj;//move the flower data over
        currentFlowerObj.flowerGridPos2            = new int[] { x2, y2 };
        currentFlowerObj.flowerGridPos             = flowerGridLoc;
        return(newFlower);
    }
示例#20
0
    private void NewPlaceableClick(Placeable placeable)
    {
        Placeable newPlaceable = Instantiate(placeable);

        newPlaceable.name = placeable.name;
        currentPlaceables.Add(newPlaceable);
        newPlaceable.transform.position = placeable.GetDefaultPosition();

        selectedPlaceable = newPlaceable;
        SelectedPlaceableChanged?.Invoke(selectedPlaceable);
    }
示例#21
0
    public void Select(Placeable block)
    {
        DeSelectCurrent();
        selected = block;
        if (selected.name == "Golden")
        {
            selected.gameObject.AddComponent <GoldBlock>();
        }

        block.activateDragMode();
    }
示例#22
0
 public bool Evaluate(Placeable placeable)
 {
     foreach (ITagCondition condition in children)
     {
         if (condition.Evaluate(placeable))
         {
             return(true);
         }
     }
     return(false);
 }
示例#23
0
        private void PreviousPlaceable()
        {
            CurrentPlaceableIndex = Modp(CurrentPlaceableIndex - 1, GameManager.Instance.Placeables.Length);

            if (CurrentPlaceable)
            {
                Destroy(CurrentPlaceable.gameObject);
            }

            CurrentPlaceable = CreateGhostPlaceable(GameManager.Instance.Placeables[CurrentPlaceableIndex]);
        }
示例#24
0
        private void NextPlaceable()
        {
            CurrentPlaceableIndex = (CurrentPlaceableIndex + 1) % GameManager.Instance.Placeables.Length;

            if (CurrentPlaceable)
            {
                Destroy(CurrentPlaceable.gameObject);
            }

            CurrentPlaceable = CreateGhostPlaceable(GameManager.Instance.Placeables[CurrentPlaceableIndex]);
        }
    /// <summary>
    /// Places the placeable at the <see cref="placementPosition"/>, updates player's current gold and also the <see cref="lastPlacedPosition"/>.
    /// </summary>
    private void PlacePlaceable()
    {
        Player.Instance.Gold -= activePlaceable.GoldCost;

        activePlaceable.IsPlaced           = true;
        activePlaceable.transform.position = placementPosition;
        activePlaceable = null;

        lastPlacedPosition = placementPosition;
        //currentRotationDegrees = 0;
    }
示例#26
0
    public void SetObjectToPlace(Placeable obj)
    {
        if (m_objectToPlace)
        {
            m_objectToPlace.CancelPlacement();
        }

        m_objectToPlace = null;
        m_preview       = null;
        m_objectToPlace = obj;
    }
 // Use this for initialization
 void Start()
 {
     gameStore = FindObjectOfType <Store>();
     outline   = GetComponent <OutlineComponent>();
     outline.Enable();
     outline.setParticles(false);
     dragging   = true;
     pointer    = GetComponentInChildren <ArrowPointer>();
     placement  = GetComponent <Placeable>();
     selectable = GetComponent <Selectable>();
 }
示例#28
0
 private void TriggerRemoveTest(Placeable p1, Placeable p2, Ksids ksids)
 {
     if (p2.IsTrigger && ksids.IsParentOrEqual(p1.Ksid, p2.TriggerTargets))
     {
         p2.RemoveTarget(p1);
     }
     if (p1.IsTrigger && ksids.IsParentOrEqual(p2.Ksid, p1.TriggerTargets))
     {
         p1.RemoveTarget(p2);
     }
 }
示例#29
0
 private void PlaceElement(Placeable placeablePrefab)
 {
     if (placeablePrefab == null)
     {
         // TODO: Indicate there was no element to place
         return;
     }
     placeable = Instantiate(placeablePrefab, transform);
     available = false;
     overlayUI.SetActive(false);
 }
示例#30
0
 public void ToggleTooltip(Placeable placeab = null)
 {
     if (placeab != null)
     {
         tooltip.gameObject.SetActive(true);
         tooltip.SetTooltip(placeab);
     }
     else
     {
         tooltip.gameObject.SetActive(false);
     }
 }
 public GameObjectSaveEventArgs(Placeable placeable)
 {
     this.ActivePlaceable = placeable;
 }