Esempio n. 1
0
    public void HireCrewMember(PlayerShip player, SpaceStation fromStation, CrewMember crewMember)
    {
        Debug.Assert(fromStation.AvailableCrew.Contains(crewMember), "can't buy crew who aren't available to buy");

        var ship = player.Ship;
        Debug.Assert(ship != null, "can't buy stuff without a ship");

        //check ship has space
        var passengerCount = ship.GetPassengers().Count();
        if (passengerCount == ship.CurrentStats.PassengerCapacity)
        {
            throw new InvalidOperationException("no room for more passengers");
        }

        //check player has enough money
        var price = GetHirePrice(crewMember);
        if (player.Money < price)
        {
            throw new InvalidOperationException("player can't afford price of " +price);
        }

        player.AddMoney(-price);
        crewMember.Assign(ship, CrewAssignment.Passenger);
        fromStation.AvailableCrew.Remove(crewMember);
    }
 /// <summary>
 /// Check if the drag stopped over a Position UI element.
 /// </summary>
 private void CheckPlacement()
 {
     foreach (var result in _raycastResults)
     {
         var positionUI = result.gameObject.GetComponent <PositionUI>();
         if (positionUI != null)
         {
             var position   = positionUI.Position;
             var crewMember = positionUI.CrewMemberUI;
             TrackerEventSender.SendEvent(new TraceEvent("CrewMemberPositioned", TrackerAsset.Verb.Interacted, new Dictionary <TrackerContextKey, object>
             {
                 { TrackerContextKey.CrewMemberName, CrewMember.Name },
                 { TrackerContextKey.PositionName, position },
                 { TrackerContextKey.PreviousCrewMemberInPosition, crewMember != null ? crewMember.CrewMember.Name : "Null" },
                 { TrackerContextKey.PreviousCrewMemberPosition, _currentPlacement != null ? _currentPlacement.Position : Position.Null }
             }, GameObjectTracker.TrackedGameObject.Npc));
             SUGARManager.GameData.Send("Place Crew Member", CrewMember.Name);
             SUGARManager.GameData.Send("Fill Position", position.ToString());
             Place(positionUI);
             //reset the position and meeting UIs
             UIManagement.PositionDisplay.Display();
             UIManagement.MemberMeeting.Display();
             return;
         }
     }
     //remove this CrewMember from their position if they were in one
     CrewMember.Assign(Position.Null);
     OnReset();
     //reset the position and meeting UIs
     UIManagement.PositionDisplay.Display();
     UIManagement.MemberMeeting.Display();
 }
    /// <summary>
    /// Place the CrewMember to be in-line with the Position it is now paired with
    /// </summary>
    public void Place(PositionUI positionUI, bool swap = false)
    {
        if (!swap && _currentPlacement)
        {
            _currentPlacement.RemoveCrew();
        }
        var currentPositionCrew = positionUI.CrewMemberUI;
        var positionTransform   = positionUI.RectTransform();

        transform.SetParent(null, false);
        CrewMember.Assign(positionUI.Position);
        positionUI.LinkCrew(this);
        //if this CrewMember isn't being placed due to a swap, check if there's a CrewMember in this position and cause a swap
        if (!swap)
        {
            if (currentPositionCrew != null)
            {
                if (_currentPlacement != null)
                {
                    currentPositionCrew.Place(_currentPlacement, true);
                }
                else
                {
                    currentPositionCrew.OnReset();
                }
            }
        }
        //set size and position
        transform.SetParent(positionTransform, false);
        _aspectFitter.aspectMode = AspectRatioFitter.AspectMode.FitInParent;
        transform.position       = positionTransform.position;
        transform.RectTransform().anchoredPosition = Vector2.zero;
        _currentPlacement = positionUI;
        SetPosition(positionUI.Position);
        //update current position button
        UIManagement.Tutorial.ShareEvent(GetType().Name, MethodBase.GetCurrentMethod().Name, CrewMember.Name);
        SetSortValue(_sortValue);
    }