Exemple #1
0
        public virtual Consumption TryTrigger(IContactReactor reactor, ContactEvent contactEvent, int compatibleMounts)
        {
            //Debug.Log("TryTrigger Basic Inv. compat with: " + compatibleMounts + " defMountId: " + defaultMounting.id + " defMask: " + defaultMountingMask);

            IInventoryable <T> iven = reactor as IInventoryable <T>;

            if (ReferenceEquals(iven, null))
            {
                return(Consumption.None);
            }

            if (contactGroups != 0)
            {
                IContactGroupsAssign groups = contactEvent.contactTrigger.ContactGroupsAssign;
                int triggermask             = ReferenceEquals(groups, null) ? 0 : groups.Mask;
                if ((contactGroups.Mask & triggermask) == 0)
                {
                    //Debug.Log("Try trigger... ContactGroup mismatch " + contactGroups.Mask + "<>" + triggermask);
                    return(Consumption.None);
                }
            }

            /// Return if the object being picked up exceeds remaining inventory.
            if (TestCapacity(reactor as IInventoryable <T>) == false)
            {
                //Debug.Log(name + " failed");
                return(Consumption.None);
            }

            /// If both are set to 0 (Root) then consider that a match, otherwise zero for one but not the other is a mismatch (for now)
            if ((compatibleMounts == defaultMountingMask) || (compatibleMounts & defaultMountingMask) != 0)
            {
                // TODO: partial consumption handling needed

                //Debug.Log(name + " <> " + (trigger as Component).name + " <b>success</b>: " + compatibleMounts + " <> " + defaultMountingMask);
                return(Consumption.All);
            }
            else
            {
                //Debug.Log(name + " <> " + (trigger as Component).name + " failed: " + compatibleMounts + " <> " + defaultMountingMask);
                return(Consumption.None);
            }
        }
Exemple #2
0
 public Mount TryPickup(IContactReactor reactor, ContactEvent contactEvent)
 {
     return(DefaultMount);
 }
Exemple #3
0
        public Consumption TryTrigger(IContactReactor icontactReactor, ContactEvent contactEvent, int compatibleMounts)
        {
            var reactor = (icontactReactor as IVitalsContactReactor);

            if (ReferenceEquals(reactor, null))
            {
                return(Consumption.None);
            }

            /// First test to see if the contacting and contacted are a groups match - if not return false.
            if (contactGroups != 0)
            {
                //var groups = (reactor as Component).GetComponent<ContactGroupAssign>();
                IContactGroupsAssign groups = contactEvent.contactTrigger.ContactGroupsAssign;

                int triggermask = ReferenceEquals(groups, null) ? 0 : groups.Mask;
                if ((contactGroups.Mask & triggermask) == 0)
                {
#if UNITY_EDITOR
                    Debug.Log(name + " SyncVitals.TryTrigger() ContactGroup Mismatch. Cannot pick up '" + (contactEvent.contactTrigger as Component).transform.root.name + "' because its has a non-matching ContactGroupAssign.");
#endif
                    return(Consumption.None);
                }
            }

            /// If both are set to 0 (Root) then consider that a match, otherwise zero for one but not the other is a mismatch (for now)
            if ((compatibleMounts != defaultMountingMask) && (compatibleMounts & defaultMountingMask) == 0)
            {
                return(Consumption.None);
            }

            Vital vital = vitals.GetVital(reactor.VitalNameType);
            if (vital == null)
            {
                return(Consumption.None);
            }

            /// Apply changes resulting from the trigger. Return true if affected/consumed. This bool is used to inform whether the trigger should despawn/pickup.

            //double charge = vpr.Charge;
            Consumption consumed;

            double amountConsumed;
            {
                /// Apply to vital if vital has authority.
                if (IsMine)
                {
                    double discharge = reactor.DischargeValue(contactEvent.contactType);
                    amountConsumed = vitals.ApplyCharges(discharge, reactor.AllowOverload, reactor.Propagate);
                }
                /// Vital does not belong to us, but we want to know IF it would have been consumed for prediction purposes.
                else
                {
                    amountConsumed = vital.TestApplyChange(reactor, contactEvent);
                }
            }

            var consumable = icontactReactor as IVitalsConsumable;
            if (!ReferenceEquals(consumable, null))
            {
                consumed = TestConsumption(amountConsumed, consumable, contactEvent);
            }
            else
            {
                consumed = Consumption.None;
            }

            return(consumed);
        }