/// <summary> /// Projectiles report hits back to the launcher, and they are queued for networking and local simulation. /// </summary> /// <param name="hit"></param> public void QueueHit(NetworkHit hit) { if (IsMine) { projectileHitQueue.Enqueue(hit); } }
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 }
///// <summary> ///// ///// </summary> ///// <returns>Returns true if consumed.</returns> //public static Mount TryVitalPickup(this ContactEvent contactEvent, float value, bool allowOverload, bool onlyPickupIfUsed) //{ // var ivc = contactEvent.itc as IVitalsComponent; // if (ReferenceEquals(ivc, null)) // return null; // var vital = contactEvent.triggeringObj as Vital; // //var vital = ivc.Vitals.GetVital(vitalNameType); // if (ReferenceEquals(vital, null)) // return null; // /// Apply to vital if vital has authority. // if (ivc.IsMine) // { // float remainder = vital.ApplyChange(value, allowOverload); // return (!onlyPickupIfUsed || value != remainder) ? ivc.DefaultMount : null; // } // /// Vital does not belong to us, but we want to know IF it would have been consumed for prediction purposes. // else // { // if (onlyPickupIfUsed) // { // float remainder = vital.TestApplyChange(value, allowOverload); // return value != remainder ? ivc.DefaultMount : null; // } // return ivc.DefaultMount; // } //} public static void ProcessHit(this NetworkHit hit, float damage, HitGroupValues multipliers, int bitsForHitGroupMask) { //var go = UnifiedNetTools.FindGameObjectByNetId(hit.netObjId); #if PUN_2_OR_NEWER var netObj = PhotonView.Find(hit.netObjId).GetComponent <NetObject>(); var collider = netObj.indexedColliders[hit.colliderId]; /// Look for IDamageable relative to the collider var iDamageable = collider.GetComponentInParent <IDamageable>(); if (ReferenceEquals(iDamageable, null)) { return; } if (iDamageable.IsMine) { int mask = hit.hitMask; /// Some totally arbitrary logic for how to deal with the HitGroups. TODO: Something real here please if (mask != 0) { float multiplier = 1f; float mitigation = 1f; for (int hg = 0; hg < bitsForHitGroupMask; ++hg) { if ((mask & 1 << hg) != 0) { int index = hg + 1; multiplier = System.Math.Max(multiplier, multipliers.values[index]); mitigation = System.Math.Min(mitigation, multipliers.values[index]); } } //Debug.Log("Hit " + mask + " dmg:" + damage + " / " + mitigation + " / " + multiplier); iDamageable.ApplyDamage(damage * mitigation * multiplier); } else { iDamageable.ApplyDamage(damage); } } #endif }
private string GetHostnamePort(NetworkHit nh) { if (nh == null) { return(null); } string netUri = nh.UriAsString; //netbeagle://164.99.153.134:8888/searchToken?http:///.... string[] f1, f2 = netUri.Split('?'); if (f2.Length > 1) { f1 = f2[0].Split('/'); if (f1.Length > 1) { return(f1[2]); } } return(null); }
public static void DoQueryResponseHandler(IAsyncResult ar) { ReqContext rc = (ReqContext)ar.AsyncState; IQueryable iq = rc.GetQueryable; BeagleWebService wsp = rc.GetProxy; IQueryResult result = rc.GetResult; int count = 0; //bool hitRejectsLogged = false; try { SearchResult resp = wsp.EndBeagleQuery(ar); if ((resp != null) && (resp.numResults > 0)) { if (rc.SearchToken == null) { rc.SearchToken = resp.searchToken; } //NetContext nc = new NetContext(wsp, resp.searchToken); HitResult[] hres = resp.hitResults; ArrayList nwhits = new ArrayList(); for (int i = 0; i < hres.Length; i++) { try { HitResult hr = hres[i]; Hit hit = new NetworkHit(); //[Uri Format] netbeagle://164.99.153.134:8888/searchToken?http:///.... if (hr.uri.StartsWith(NetworkedBeagle.BeagleNetPrefix)) { hit.UriAsString = hr.uri; } else { string[] fragments = hr.uri.Split('/'); string hostNamePort = fragments[2]; hit.UriAsString = NetworkedBeagle.BeagleNetPrefix + hostNamePort + "/" + resp.searchToken + "?" + hr.uri; } hit.Type = hr.resourceType; hit.MimeType = hr.mimeType; hit.Source = "Network"; //hit.Source = hr.source; hit.Score = hr.score; if (hr.properties.Length > 0) { foreach (HitProperty hp in hr.properties) { Property p = Property.New(hp.PKey, hp.PVal); p.IsMutable = hp.IsMutable; p.IsSearched = hp.IsSearched; hit.AddProperty(p); } } //Add Snippet ((NetworkHit)hit).snippet = hr.snippet; //if (hr.snippet != null) //log.Debug("\nNBH: URI" + i + "=" + hr.uri + "\n Snippet=" + hr.snippet); ((NetworkHit)hit).context = new NetContext(hr.hashCode); //Add NetBeagleQueryable instance hit.SourceObject = iq; hit.SourceObjectName = ((NetworkedBeagle)iq).Name; nwhits.Add(hit); count++; } catch (Exception ex2) { log.Warn("Exception in NetBeagleHandler: DoQueryResponseHandler() while processing NetworkHit: {0} from {1}\n Reason: {2} ", hres[i].uri, wsp.Hostname + ":" + wsp.Port, ex2.Message); //log.Error ("Exception StackTrace: " + ex.StackTrace); } } //end for if (nwhits.Count > 0) { result.Add(nwhits); } /* * if ((! result.Add (nwhits)) && (! hitRejectsLogged)) * { * hitRejectsLogged = true; * log.Info("NetBeagleHandler: Network Hits rejected by HitRegulator. Too many Hits!"); * } */ log.Info("NetBeagleHandler: DoQueryResponseHandler() Got {0} result(s) from Index {1} from Networked Beagle at {2}", count, resp.firstResultIndex, wsp.Hostname + ":" + wsp.Port); int index = resp.firstResultIndex + resp.numResults; if (index < resp.totalResults) { log.Debug("NetBeagleHandler: DoQueryResponseHandler() invoking GetResults with index: " + index); string searchToken = resp.searchToken; GetResultsRequest req = new GetResultsRequest(); req.startIndex = index; req.searchToken = searchToken; IAsyncResult ar2; ar2 = wsp.BeginGetResults(req, NetBeagleHandler.DoQueryResponseHandler, rc); return; } } //end if else { if (resp == null) { log.Warn("NetBeagleHandler: DoQueryResponseHandler() got Null response from EndBeagleQuery() !"); } } } catch (Exception ex) { log.Error("Exception in NetBeagleHandler: DoQueryResponseHandler() - {0} - for {1} ", ex.Message, wsp.Hostname + ":" + wsp.Port); } //Signal completion of request handling rc.RequestProcessed = true; }
public static int GenericHitscanNonAlloc(this HitscanDefinition hd, Transform origin, ref List <NetworkHit> hitscanHits, ref int nearestIndex, Realm realm, bool showDebugWidgets = false) { if (hitscanHits == null) { hitscanHits = reusableHitscanHitList; } int nearestRayHit = -1; nearestIndex = -1; int count = GenericHitscanNonAlloc(hd, origin, ref reusableColliderArray, ref reusableRayHitArray, ref nearestRayHit, realm, showDebugWidgets); reusableGameObjIntDict.Clear(); hitscanHits.Clear(); if (count > 0) { /// Check each collider hit for its hitgroup and its rootgameobject/netid - add to our outgoing List<HitscanHit> for (int i = 0; i < count; ++i) { var hit = reusableColliderArray[i]; /// We are only interested in objects with IDs /// TODO: this assumes root only PhotonViews - which may not always be the case var netObj = hit.GetComponentInParent <emotitron.Networking.NetObject>(); if (ReferenceEquals(netObj, null)) { continue; } var netId = netObj.NetObjId; var hitgroupassign = hit.GetComponent <IHitGroupAssign>(); var mask = (ReferenceEquals(hitgroupassign, null)) ? 0 : hitgroupassign.Mask; int existingIndex; bool exists = reusableGameObjIntDict.TryGetValue(netId, out existingIndex); int colliderId = netObj.colliderLookup[hit]; if (exists) { var hitscanHit = hitscanHits[existingIndex]; //Debug.Log("EXIST Hitscan hit on " + origin.name + "/" + hit.name + " m: " + mask + "->" + (hitscanHit.hitMask | mask)); hitscanHits[existingIndex] = new NetworkHit(hitscanHit.netObjId, hitscanHit.hitMask | mask, colliderId); /// If we are adding the nearest raycast, log it. if (i == nearestRayHit) { nearestIndex = existingIndex; } } else { //Debug.Log("NEW Hitscan hit on " + rootGO.name + "/" + hit.name + " " + mask); /// If we are adding the nearest raycast, log it. if (i == nearestRayHit) { nearestIndex = hitscanHits.Count; } hitscanHits.Add(new NetworkHit(netId, mask, colliderId)); reusableGameObjIntDict.Add(netId, hitscanHits.Count - 1); } } } return(reusableGameObjIntDict.Count); }