示例#1
0
    public void CalculateVelocity(UndirecteGraph <HouseNode, Edge <HouseNode> > graph, float speed)
    {
        List <Edge <HouseNode> > connectedEdges = graph.GetConnectedEdges(this);
        Vector3 velocity = Vector3.zero;

        foreach (var edge in connectedEdges)
        {
            HouseNode connectedVertex = edge.GetOtherVertex(this);
            float     weight          = (float)edge.Weight;
            Vector3   direction       = connectedVertex.Position - this.Position;
            velocity += direction * (direction.magnitude - weight);
        }
        _velocity = velocity * speed;
    }
示例#2
0
    public static IEnumerator SummonSatanCoroutine(GOAPEntity ent)
    {
        Node      startingPoint = NodeList.allNodes.OrderBy(a => { return(Vector3.Distance(a.transform.position, ent.transform.position)); }).First();
        HouseNode target        = NodeList.allNodes
                                  .Select(a => { return(a.GetComponent <HouseNode>()); })
                                  .Where(a => a != null && !a.owned && !a.constructed)
                                  .OrderBy(a => { return(Vector3.Distance(a.transform.position, ent.transform.position)); })
                                  .First();


        var path = Algorithms.AStar(
            startingPoint,
            a => a == target,
            a => Vector3.Distance(target.transform.position, a.transform.position),
            a =>
        {
            return(a.neighbors.Where(b => b.gameObject.activeSelf).Select(n => new Arc <Node>().SetArc(n, Vector3.Distance(n.transform.position, a.transform.position))));
        }
            );

        while (path.Count > 0)
        {
            ent.transform.forward   = new Vector3(path.Peek().transform.position.x - ent.transform.position.x, ent.transform.forward.y, path.Peek().transform.position.z - ent.transform.position.z);
            ent.transform.position += ent.transform.forward * Mathf.Min(Vector3.Distance(path.Peek().transform.position, ent.transform.position), ent.speed * Time.deltaTime);
            if (Vector3.Distance(path.Peek().transform.position, ent.transform.position) <= 2f)
            {
                path.Pop();
            }
            yield return(new WaitForEndOfFrame());
        }
        var satanSymbol = ent.transform.GetChild(0).gameObject;

        satanSymbol.SetActive(true);
        target.constructed = true;
        target.owned       = true;

        while (true)
        {
            satanSymbol.transform.eulerAngles += satanSymbol.transform.forward * 50f * Time.deltaTime;
            satanSymbol.transform.localScale  += (Vector3.one * Time.deltaTime);
            yield return(new WaitForEndOfFrame());
        }

        ent.Sequence.First().Effects(ent.Current, ent.Current);
        ent.Sequence = ent.Sequence.Skip(1);
        if (ent.Sequence.Count() > 0)
        {
            ent.Sequence.First().Act(ent);
        }
    }
示例#3
0
    public static IEnumerator OpenHouseCoroutine(GOAPEntity ent)
    {
        Node      startingPoint = NodeList.allNodes.OrderBy(a => { return(Vector3.Distance(a.transform.position, ent.transform.position)); }).First();
        HouseNode target        = NodeList.allNodes
                                  .Select(a => { return(a.GetComponent <HouseNode>()); })
                                  .Where(a => a != null && ent.Current.Keys.Contains(a.keyId))
                                  .OrderBy(a => { return(Vector3.Distance(a.transform.position, ent.transform.position)); })
                                  .First();


        var path = Algorithms.AStar(
            startingPoint,
            a => a == target,
            a => Vector3.Distance(target.transform.position, a.transform.position),
            a =>
        {
            return(a.neighbors.Where(b => b.gameObject.activeSelf).Select(n => new Arc <Node>().SetArc(n, Vector3.Distance(n.transform.position, a.transform.position))));
        }
            );

        while (path.Count > 0)
        {
            ent.transform.forward   = new Vector3(path.Peek().transform.position.x - ent.transform.position.x, ent.transform.forward.y, path.Peek().transform.position.z - ent.transform.position.z);
            ent.transform.position += ent.transform.forward * Mathf.Min(Vector3.Distance(path.Peek().transform.position, ent.transform.position), ent.speed * Time.deltaTime);
            if (Vector3.Distance(path.Peek().transform.position, ent.transform.position) <= 2f)
            {
                path.Pop();
            }
            yield return(new WaitForEndOfFrame());
        }
        target.constructed = true;
        target.owned       = true;

        ent.Sequence.First().Effects(ent.Current, ent.Current);
        ent.Sequence = ent.Sequence.Skip(1);
        if (ent.Sequence.Count() > 0)
        {
            ent.Sequence.First().Act(ent);
        }
    }
示例#4
0
    BeerTree MapGenerator(int numberOfSwitches)
    {
        SwitchNode parentSwitch = new SwitchNode(new Vector2(0.0f, 0.0f), "SWITCH_ROOT", new Switch(), true);
        BeerTree   bT           = new BeerTree(parentSwitch);

        int numOfSwitches = numberOfSwitches;

        float y = 0.0f;
        int   idSwitchCounter = 1;
        int   numOfHouses     = 0;
        int   idHouseCounter  = 1;

        for (int i = 0; i < numOfSwitches; i++)
        {
            y = y - 3;
            SwitchNode newSwitch = new SwitchNode(new Vector2(0.0f, y), "SWITCH_" + idSwitchCounter++, new Switch(), false);
            if (i == numOfSwitches - 1)
            {
                lastSwitchYcoordinate = y;
            }

            numOfHouses = RandomUtils.GetRandomNumber(1, 4);

            if (i == 0)
            {
                bT.AddSwitch(newSwitch, "SWITCH_ROOT");
            }
            else
            {
                bT.AddSwitch(newSwitch, parentSwitch.nodeId);
            }
            parentSwitch = newSwitch;

            switch (numOfHouses)
            {
            case 1:
            {
                HouseNode leftHouse = new HouseNode(new House(), new Vector2(-5.0f, newSwitch.coordinates.y), "HOUSE_" + idHouseCounter++);
                bT.AddHouse(leftHouse, newSwitch.nodeId);
                break;
            }

            case 2:
            {
                HouseNode rightHouse = new HouseNode(new House(), new Vector2(5.0f, newSwitch.coordinates.y), "HOUSE_" + idHouseCounter++);
                bT.AddHouse(rightHouse, newSwitch.nodeId);
                break;
            }

            default:
            {
                HouseNode leftHouse = new HouseNode(new House(), new Vector2(-5.0f, newSwitch.coordinates.y), "HOUSE_" + idHouseCounter++);
                bT.AddHouse(leftHouse, newSwitch.nodeId);
                HouseNode rightHouse = new HouseNode(new House(), new Vector2(5.0f, newSwitch.coordinates.y), "HOUSE_" + idHouseCounter++);
                bT.AddHouse(rightHouse, newSwitch.nodeId);
                break;
            }
            }
        }

        return(bT);
    }