void AuthToTurret(BasePlayer player, AutoTurret turret, Dictionary <ulong, string> authList) { bool isOnline = false; if (turret.IsOnline()) { turret.SetIsOnline(false); isOnline = true; } turret.authorizedPlayers.Clear(); foreach (var friend in authList) { turret.authorizedPlayers.Add(new ProtoBuf.PlayerNameID { userid = friend.Key, username = friend.Value }); } turret.SendNetworkUpdateImmediate(); player.SendNetworkUpdateImmediate(); if (isOnline) { turret.SetIsOnline(true); } SendReply(player, string.Format(msg("turretSuccess"), authList.Count)); return; }
void UpdateAutoTurret(AutoTurret turret, bool justCreated = false) { CheckAutoTurretAmmo(turret); string userID = turret.OwnerID.ToString(); float turretHealth = FromPermission(userID, autoHealths, defaultAutoHealth); string ammoType = FromPermission(userID, ammoTypes, defaultAmmoType); InitializeTurret(turret, turretHealth, justCreated); turret.bulletSpeed = FromPermission(userID, bulletSpeeds, defaultBulletSpeed); turret.sightRange = FromPermission(userID, sightRanges, defaultSightRange); turret.aimCone = FromPermission(userID, aimCones, defaultAimCone); var def = ItemManager.FindItemDefinition(ammoType); if (def is ItemDefinition) { turret.ammoType = def; ItemModProjectile projectile = def.GetComponent <ItemModProjectile> (); if (projectile is ItemModProjectile) { turret.gun_fire_effect.guid = projectile.projectileObject.guid; turret.bulletEffect.guid = projectile.projectileObject.guid; } } else { PrintWarning("No ammo of type ({0})", ammoType); } turret.Reload(); turret.SendNetworkUpdateImmediate(justCreated); }
private void UpdateTurret(AutoTurret turret, bool justCreated = false) { CheckAmmo(turret); string userID = turret.OwnerID.ToString(); float turretHealth = GetHealth(userID); string ammoType = GetAmmoType(userID); bulletDamageField.SetValue(turret, GetBulletDamage(userID)); if (justCreated) { healthField.SetValue(turret, turretHealth); } maxHealthField.SetValue(turret, turretHealth); if (justCreated) { turret.InitializeHealth(turretHealth, turretHealth); } else { turret.InitializeHealth(turret.health, turretHealth); } turret.bulletSpeed = GetBulletSpeed(userID); turret.sightRange = GetSightRange(userID); turret.startHealth = turretHealth; turret.aimCone = GetAimCone(userID); var def = ItemManager.FindItemDefinition(ammoType); if (def is ItemDefinition) { turret.ammoType = def; ItemModProjectile projectile = def.GetComponent <ItemModProjectile>(); if (projectile is ItemModProjectile) { turret.gun_fire_effect.guid = projectile.projectileObject.guid; turret.bulletEffect.guid = projectile.projectileObject.guid; } } else { PrintWarning("No ammo of type ({0})", ammoType); } turret.Reload(); //turret.enableSaving = false; //turret.ServerInit(); turret.SendNetworkUpdateImmediate(justCreated); }
private bool unflipTurreT(BaseEntity turret, BasePlayer player) { try{ if (turret.transform.rotation.w != -0.00f) { return(false); } AutoTurret autoTurret = GameManager.server.CreateEntity(pf, new Vector3(turret.transform.position.x, turret.transform.position.y - 3f, turret.transform.position.z), new Quaternion(0.0f, 0.1f, 0.0f, 1.0f), true) as AutoTurret; autoTurret.Spawn(); autoTurret.health = turret.Health(); turretinv.Add(autoTurret, 0); foreach (var item in turret.GetComponent <AutoTurret>().inventory.itemList.ToList()) { if (item.info.displayName.english == ("5.56 Rifle Ammo")) { turretinv[autoTurret] = turretinv[autoTurret] + item.amount; } } turretplayer.Add(autoTurret, new AutoPlayer { }); foreach (var target in turret.GetComponent <AutoTurret>().authorizedPlayers) { turretplayer[autoTurret].players.Add(target); } Item itemn = BuildItems("ammo.rifle", turretinv[autoTurret]); if (itemn != null) { itemn.MoveToContainer(autoTurret.inventory); } turretinv.Remove(autoTurret); foreach (var entry in turretplayer[autoTurret].players) { autoTurret.authorizedPlayers.Add(entry); } turretplayer.Remove(autoTurret); autoTurret.SendNetworkUpdateImmediate(); turret.KillMessage(); return(true); } catch (System.Exception) { return(false); } }
private void AuthToTurret(AutoTurret turret, Dictionary <ulong, string> authList, BasePlayer player = null) { bool isOnline = false; if (turret.IsOnline()) { turret.SetIsOnline(false); isOnline = true; } IEnumerable <ulong> currentAuth = turret.authorizedPlayers.Select(x => x.userid); foreach (var friend in authList) { if (currentAuth.Contains(friend.Key)) { continue; } turret.authorizedPlayers.Add(new ProtoBuf.PlayerNameID { userid = friend.Key, username = friend.Value }); } turret.SendNetworkUpdateImmediate(); if (isOnline) { turret.SetIsOnline(true); } if (player != null) { player.SendNetworkUpdateImmediate(); SendReply(player, string.Format(msg("turretSuccess"), authList.Count)); } }
public void TurretInput(InputState input, BasePlayer player) { if (input == null || player == null) { return; } BUTTON.TryParse(Button, out PowerButton); if (input.WasJustPressed(PowerButton)) { bool hasPermission = permission.UserHasPermission(player.UserIDString, perms); if (!hasPermission) { player.ChatMessage(msg("NoPermissions", player.UserIDString)); return; } RaycastHit hit; if (Physics.SphereCast(player.eyes.position, 0.5f, Quaternion.Euler(player.serverInput.current.aimAngles) * Vector3.forward, out hit)) { AutoTurret autoturret = hit.GetEntity()?.GetComponent <AutoTurret>(); SamSite samsite = hit.GetEntity()?.GetComponent <SamSite>(); if (autoturret != null) { if (hit.distance >= 1.5) { return; } if (!autoturret.IsAuthed(player)) { player.ChatMessage(msg("NotAuthed", player.UserIDString)); return; } if (!IsAuthed(player, autoturret)) { player.ChatMessage(msg("NoBuildPrivilege", player.UserIDString)); return; } if (autoturret.IsOnline()) { autoturret.SetIsOnline(false); PoweredTurrets.Remove(autoturret.net.ID); } else { autoturret.SetIsOnline(true); PoweredTurrets.Add(autoturret.net.ID); } autoturret.SendNetworkUpdateImmediate(); } if (samsite != null) { if (hit.distance >= 1.5) { return; } if (!IsAuthed(player, samsite)) { player.ChatMessage(msg("NoBuildPrivilege", player.UserIDString)); return; } if (samsite.IsPowered()) { samsite.UpdateHasPower(0, 1); PoweredSams.Remove(samsite.net.ID); } else { samsite.UpdateHasPower(25, 1); PoweredSams.Add(samsite.net.ID); } samsite.SendNetworkUpdateImmediate(); } } } }