Exemple #1
0
        public virtual bool TryTrigger(IOnTrigger trigger, ref ContactEvent contactEvent, int compatibleMounts)
        {
            //Debug.Log("TryTrigger BAsic Inv. compat with: " + compatibleMounts + " defMountId: " + defaultMounting.id + " defMask: " + defaultMountingMask);

            if (validHitGroups != 0)
            {
                var hga         = contactEvent.contacted.GetComponent <HitGroupAssign>();
                int triggermask = hga ? hga.Mask : 0;
                if ((validHitGroups.Mask & triggermask) == 0)
                {
                    Debug.Log("Try trigger... HitGroup mismatch");
                    return(false);
                }
            }

            /// Return if the object being picked up exceeds remaining inventory.
            if (TestCapacity(trigger as IInventoryable <T>) == false)
            {
                return(false);
            }

            /// 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(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #2
0
        public Mount TryPickup(IOnPickup pickup, ContactEvent contactEvent)
        {
            var vital = contactEvent.triggeringObj as Vital;

            if (ReferenceEquals(vital, null))
            {
                return(null);
            }

            var   vpr          = pickup as IVitalsAffector;
            float value        = vpr.Value;
            var   defaultMount = DefaultMount;

            /// Apply to vital if vital has authority.
            if (IsMine)
            {
                float remainder = vital.ApplyChange(value, vpr.AllowOverload);
                return((!vpr.OnlyPickupIfUsed || value != remainder) ? defaultMount : null);
            }
            /// Vital does not belong to us, but we want to know IF it would have been consumed for prediction purposes.
            else
            {
                if (vpr.OnlyPickupIfUsed)
                {
                    float remainder = vital.TestApplyChange(value, vpr.AllowOverload);
                    return(value != remainder ? defaultMount : null);
                }
                return(defaultMount);
            }
        }
Exemple #3
0
        // Step #1

        public bool OnContactEvent(ref ContactEvent contactEvent)
        {
            if (!IsMine)
            {
                return(false);
            }

            switch (contactEvent.contactType)
            {
            case ContactType.Enter:
            {
                return(OnEnter(ref contactEvent));
            }

            case ContactType.Stay:
            {
                return(OnStay(ref contactEvent));
            }

            case ContactType.Exit:
            {
                return(OnExit(ref contactEvent));
            }

            case ContactType.Hitscan:
            {
                return(OnHitscan(ref contactEvent));
            }

            default:
                return(false);
            }
        }
Exemple #4
0
 public ContactEvent(ContactEvent contactEvent)
 {
     this.triggeringObj = contactEvent.triggeringObj;
     this.itc           = contactEvent.itc;
     this.contacted     = contactEvent.contacted;
     this.contacter     = contactEvent.contacter;
     this.contactType   = contactEvent.contactType;
 }
 protected virtual void SnapshotTrigger(ContactEvent triggerEvent)
 {
     //var attachedTo = triggerEvent.ivc; // UnifiedNetTools.FindComponentByNetId<IVitalsComponent>((uint)triggerEvent.ivc.NetObjId);
     //if (!ReferenceEquals(attachedTo, null))
     //{
     //	ApplyAffect(attachedTo);
     //}
 }
        public void ProcessHit(NetworkHit hit, int bitsForHitGroupMask)
        {
#if PUN_2_OR_NEWER
            var netObj = PhotonView.Find(hit.netObjId).GetComponent <NetObject>();

            var collider = netObj.indexedColliders[hit.colliderId];

            /// Look for IOnTriggeringHitscan relative to the collider
            collider.transform.GetNestedComponentsInParents(reusableContactTriggers);

            int cnt = reusableContactTriggers.Count;
            if (cnt == 0)
            {
                return;
            }

            /// Iterate all of the trigger candidates found
            for (int h = 0; h < cnt; h++)
            {
                var found = reusableContactTriggers[h];

                /// We are only interested in the found triggers if they are networked, since this is NetHit based.
                var foundNetObj = (found as Component).GetComponent <NetObject>();
                if (foundNetObj == null)
                {
                    continue;
                }

                int itcCount = triggeringComponents.Count;
                //Debug.Log("Collider " + collider.name + " " + (reusableContactTriggers[0] as Component).GetType().Name + " found: " + (found != null) + " cnt: " + itcCount);

                /// Check the found triggers against ITriggeringComponents to find valid matches
                for (int c = 0; c < itcCount; c++)
                {
                    var itc = triggeringComponents[c];

                    if (foundNetObj.pv.IsMine)
                    {
                        int mask         = hit.hitMask;
                        int hitgroupMask = mask;                         // 1 << (mask - 1); // (mask == 0) ? 0 : ((int)1 << (mask - 1));

                        /// Some totally arbitrary logic for how to deal with the HitGroups. TODO: Something real here please
                        //Debug.Log((int)validHitGroups + " mask: " + hitgroupMask);

                        /// First test for equals allows masks of Default (0) to count as a match. The second test looks for any matching bit.
                        if (validHitGroups == hitgroupMask || ((validHitGroups & hitgroupMask) != 0))
                        {
                            //Debug.Log("<b>HIT !!!</b>");
                            var contactEvent = new ContactEvent(null, itc, found as Component, this, ContactType.Hitscan);
                            found.Trigger(contactEvent);
                        }
                    }
                }
            }
#endif
        }
        public virtual void Trigger(ContactEvent contactEvent)
        {
            Debug.Log("Trigger " + name);
            int cnt = onContactEventCallbacks.Count;

            for (int i = 0; i < cnt; ++i)
            {
                onContactEventCallbacks[i].OnContactEvent(ref contactEvent);
            }
        }
Exemple #8
0
        public virtual Mount OnPickup(ContactEvent contactEvent)
        {
            var itc = contactEvent.itc as T;

            if (ReferenceEquals(itc, null))
            {
                return(null);
            }

            return(itc.TryPickup(this, contactEvent));
        }
        protected virtual void OnTrigger(TFrame frame, ContactEvent trigger)
        {
            frame.triggeredById = trigger.itc == null ? null : (int?)trigger.itc.NetObjId;

            int cnt = onVitalsTrigger.Count;

            for (int i = 0; i < cnt; ++i)
            {
                onVitalsTrigger[i].OnVitalsTrigger(frame.frameId, trigger);
            }
        }
Exemple #10
0
        protected virtual bool OnEnter(ref ContactEvent contactEvent)
        {
            /// Ignore collision with self/owner
            if (ignoreOwner && !ReferenceEquals(contactEvent.itc, null) && contactEvent.itc.NetObjId == owner.NetObjId)
            {
                return(false);
            }

            //Debug.Log("contacted: " + contactEvent.contacted.name + " thisCol" + contactEvent.contacted.transform.root.name + " contactor: " + contactEvent.contacter.name);
            OnHit(contactEvent.contacter);
            return(true);
        }
        /// <summary>
        /// Check if the ITriggeringComponent is an IVitalsComponent, and if so that it has the vital that matches the trigger.
        /// </summary>
        /// <param name="frameInt"></param>
        /// <param name="contactEvent"></param>
        /// <returns>Returns true if this triggerer is a IVitalsComponent, and contains the indicated vital type.</returns>
        public static Vital GetTriggeringVital(this ContactEvent contactEvent, VitalNameType vitalNameType)
        {
            var ivc = (contactEvent.itc as IVitalsComponent);

            if (ReferenceEquals(ivc, null))
            {
                return(null);
            }

            Vitals vitals = ivc.Vitals;
            Vital  vital  = vitals.GetVital(vitalNameType);

            return(vital);
        }
Exemple #12
0
        public virtual bool OnTrigger(ref ContactEvent contactEvent)
        {
            var itc = contactEvent.itc as T;

            if (itc == null)
            {
                return(false);
            }

            ///TODO: this should eventually not be needed
            contactEvent.triggeringObj = itc;

            return(itc.TryTrigger(this, ref contactEvent, compatibleMountsMask));
        }
Exemple #13
0
        /// <summary>
        /// Responds to State change from SyncState
        /// </summary>
        public void OnStateChange(ObjState state, Transform attachmentTransform, Mount attachTo = null, bool isReady = true)
        {
            /// If IsMine, we already Fired this in order to test for consumption.
            if (!IsMine)
            {
                var currentAttachedIVC = (attachTo) ? attachTo.GetComponentInParent <IContacting>() : null;
                var triggerEvent       = new ContactEvent(null, currentAttachedIVC, null, null, ContactType.Enter);

                for (int i = 0; i < onPickupCallbacks.Count; ++i)
                {
                    onPickupCallbacks[i].OnPickup(triggerEvent);
                }
            }
        }
Exemple #14
0
        /// <summary>
        /// Find the first valid trigger in whatever trigger events have been registered.
        /// </summary>
        protected bool GetFirstTriggerEvent(Frame frame, out ContactEvent contactEvent)
        {
            while (queuedContactEvents.Count > 0)
            {
                contactEvent = queuedContactEvents.Dequeue();
                if (OnTrigger(frame, ref contactEvent))
                {
                    return(true);
                }
            }

            contactEvent = new ContactEvent();
            return(false);
        }
Exemple #15
0
        protected virtual bool EnqueueEvent(ref ContactEvent contactEvent)
        {
            /// TODO: need to put a consumption validity test here
            IContacting ivc = contactEvent.itc;

            if (ReferenceEquals(ivc, null))
            {
                return(false);
            }

            queuedContactEvents.Enqueue(contactEvent);

            return(true);
        }
        /// <summary>
        /// Primary triggering event
        /// </summary>
        public virtual void OnTriggeringExit(ContactEvent contactEvent)
        {
            if (!IsMine)
            {
                return;
            }

            /// Only log this if we are responding ot OnEnter
            if ((triggerOn & ContactType.Exit) == 0)
            {
                return;
            }

            queueContactEvent.Enqueue(contactEvent);
        }
        protected override bool ProcessContactEvent(ref ContactEvent contactEvent)
        {
            IDamageable vitals = (contactEvent.itc as IDamageable);

            if (ReferenceEquals(vitals, null))
            {
                return(false);
            }

            float value = GetValueForTriggerType(contactEvent.contactType);

            if (!ReferenceEquals(vitals, null))
            {
                vitals.ApplyDamage(value);
            }

            return(true);
        }
Exemple #18
0
        /// <summary>
        /// Attempt a trigger. Returns true if a triggerEvent results in a valid collision.
        /// </summary>
        protected virtual bool OnTrigger(Frame frame, ref ContactEvent contactEvent)
        {
            frame.triggeredById = contactEvent.itc == null ? null : (int?)contactEvent.itc.NetObjId;

            int cnt = onTriggerCallbacks.Count;

            for (int i = 0; i < cnt; ++i)
            {
                //Debug.Log("onTriggerCallbacks? " + (onTriggerCallbacks[i] as Object).name + " : " + (onTriggerCallbacks[i] as Object).GetType().Name);

                if (onTriggerCallbacks[i].OnTrigger(ref contactEvent))
                {
                    return(true);
                }
            }

            //Debug.Log(name + " OnTrigger try to find mount :" + found.name);
            return(false);
        }
Exemple #19
0
        /// <summary>
        /// Pickup trigger code on Owner. This fires if OnTrigger
        /// </summary>
        protected virtual void OnPickup(Frame frame, ContactEvent contactEvent)
        {
            Mount mount = null;

            /// Callbacks for Pickup - Trigger effect
            for (int i = 0; i < onPickupCallbacks.Count; ++i)
            {
                var usedmount = onPickupCallbacks[i].OnPickup(contactEvent);

                if (usedmount)
                {
                    mount = usedmount;
                }
            }

            if (mount)
            {
                syncState.HardMount(mount);
            }
        }
        /// <summary>
        /// Primary triggering event
        /// </summary>
        public virtual void OnContactEvent(ContactEvent contactEvent)
        {
            if (!IsMine)
            {
                return;
            }

            var ivc = contactEvent.itc as IVitalsComponent;

            if (ReferenceEquals(ivc, null))
            {
                return;
            }

            /// Only log this if we are responding ot OnEnter
            if ((triggerOn & ContactType.Enter) == 0)
            {
                return;
            }

            queueContactEvent.Enqueue(contactEvent);
        }
Exemple #21
0
        public bool TryTrigger(IOnTrigger trigger, ref ContactEvent contactEvent, int compatibleMounts)
        {
            if (!useHitGroups || validHitGroups != 0)
            {
                var hga         = contactEvent.contacted.GetComponent <HitGroupAssign>();
                int triggermask = hga ? hga.Mask : 0;
                if ((validHitGroups.Mask & triggermask) == 0)
                {
#if UNITY_EDITOR
                    Debug.Log(name + " SyncVitals.TryTrigger() HitGroup Mismatch. Cannot pick up '" + hga.transform.root.name + "' because its has a non-matching HitGroupAssign.");
#endif
                    return(false);
                }
            }

            ///TODO: Make this into an interface rather than this component type
            var otherVitalNameType = (trigger as IVitalsAffector);

            Vital vital = vitals.GetVital(otherVitalNameType.VitalNameType);
            if (vital == null)
            {
                return(false);
            }

            /// 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)
            {
                contactEvent = new ContactEvent(contactEvent)
                {
                    triggeringObj = vital
                };
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #22
0
 protected virtual bool OnExit(ref ContactEvent contactEvent)
 {
     return(false);
 }
Exemple #23
0
 public virtual Mount TryPickup(IOnPickup trigger, ContactEvent contactEvent)
 {
     return(DefaultMount);
 }
Exemple #24
0
 protected virtual bool OnHitscan(ref ContactEvent contactEvent)
 {
     return(EnqueueEvent(ref contactEvent));
 }
Exemple #25
0
 protected virtual bool OnEnter(ref ContactEvent contactEvent)
 {
     return(EnqueueEvent(ref contactEvent));
 }