public void SpawnCustomerGroup(CustomerSpawnStrategy strategy, int groupNum, SpawnPosition selectedSpawner)
    {
        if (selectedSpawner == null)
        {
            return;
        }

        CustomerData leaderData = GetNextSpawningCustomer(strategy);
        Customer     leader     = SpawnCustomer(leaderData, selectedSpawner);

        leader.SetAsLeader();
        Blackboard      leader_bb = leader.GetComponent <Blackboard>();
        CustomerGroup   group     = CustomerGroup.CreateGroup(leader);
        List <Customer> members   = new List <Customer>();

        //We can get positive relations from relaters, for now just get from closest relations
        for (int i = 0; i < leaderData.PositiveRelations.Count; ++i)
        {
            if (i >= groupNum - 1)
            {
                break;
            }

            //TODO add strategy here to choose relations
            Relationship relationShip = leaderData.PositiveRelations[i];
            CustomerData related      = LookupCustomer(relationShip.WithWho);
            Customer     member       = SpawnCustomer(related, selectedSpawner);

            members.Add(member);

            Blackboard member_bb = member.GetComponent <Blackboard>();
            if (member_bb)
            {
                member_bb.AddOrModifyBBValue <CustomerGroup>("Group", group);
            }
        }

        group.ExpandGroup(members);

        //add group into all members' blackboard
        if (leader_bb)
        {
            leader_bb.AddOrModifyBBValue <CustomerGroup>("Group", group);
        }
    }
Example #2
0
    public override void OnEnterState(IStateMachineOwner owner)
    {
        if (owner.GetType() != typeof(Customer))
        {
            Object ownerObject = owner as Object;
            Debug.LogError(string.Format("{0} is not customer, cannot use GotoSeatsState", ownerObject.name));
            throw new System.Exception("Wrong State Usage");
        }

        Customer customer = owner as Customer;

        Debug.Log(string.Format("{0} Enter GotoSeatsState", customer.Data.CharacterName));
        Utils.GetGameManager().GetUIManager().PopoutNewMessage(customer.gameObject, "Enter GotoSeatsState");

        if (customer.GetIsLeader())
        {
            InnManager innManager = Utils.GetGameManager().GetInnManager();

            Table table;
            if (innManager.QueryTable(customer, out table))
            {
                Vector3 des = table.PopOutSeats(customer);

                Blackboard leader_bb = customer.GetComponent <Blackboard>();
                leader_bb.AddOrModifyBBValue <Table>("Table", table);

                CustomerGroup group = CustomerGroup.GetGroupViaLeader(customer);

                foreach (Customer member in group._Members)
                {
                    Blackboard member_bb = member.GetComponent <Blackboard>();
                    member_bb.AddOrModifyBBValue <Table>("Table", table);
                }

                customer.MoveToLocation(des);
                _destinationSettled = true;
            }
        }
        else
        {
            //non-leader should follow leader decisions.
        }
    }