package Gameplay { import flash.display.DisplayObject; import flash.media.Sound; import gs.TweenLite; public class Weapon { // Gun data public var name : String; public var graphic : DisplayObject; public var frames_per_bullet : int; // number of non-shooting frames that pass before next shot public var frames_per_reload : Number; // number of frames before gun is reloaded public var penetration : int; // number of zombies the round will penetrate through public var spread : int; // the angle in degrees that the gun might fire off center public var range : int; // How far the bullet will travel public var ammoLoaded : int; // Ammo currently in the gun public var ammoLeft : int; // Total ammo remaining public var damage : int; // damage the gun will do public var clipSize : int; // The number of bullets in a clip public var sound : int; // range that sound attracts attention public var knockback : int; // how far the gun knocks back its target public var velocity : Number; // velocity of the round. .7 is a good value, change to get the desired effect public var shots : int; // the number of shots discharged each time the weapon is fired. public var cost : int; // cost of the weapon in the store public var primary : Boolean; // true for primary, false for secondary public var type : int; // Index value from WeaponIndex public var reloading : Boolean = false; // Usage statistics public var shots_fired : int = 0; public var misses : int = 0; public var level_fired : int = 0; public var level_misses : int = 0; public function Weapon(weaponIndex : int = 0) { type = weaponIndex; switch (weaponIndex) { //SECONDARY WEAPONS case WeaponIndex.PISTOL: name = "Pistol"; graphic = new g_pistol(); ammoLeft = 96; ammoLoaded = 12; penetration = 1; range = 400; frames_per_bullet = 12; frames_per_reload = 1.8; spread = 3; damage = 20; sound = 350; knockback = 5; velocity = .90; shots = 1; clipSize = 12; primary = false; cost = 200; break; case WeaponIndex.MAGNUM: name = "Desert Eagle"; graphic = new g_magnum(); ammoLeft = 49; ammoLoaded = 7; penetration = 4; range = 500; frames_per_bullet = 30; frames_per_reload = 1.23; spread = 4; damage = 50; sound = 650; knockback = 15; velocity = 1.0; shots = 1; clipSize = 7; primary = false; cost = 1000; break; case WeaponIndex.MAC10: name = "MAC-10"; graphic = new g_mac10(); ammoLeft = 150; ammoLoaded = 30; penetration = 1; range = 300; frames_per_bullet = 5; frames_per_reload = 2; spread = 10; damage = 10; sound = 400; knockback = 1; velocity = .90; shots = 1; clipSize = 30; primary = false; cost = 1200; break; //PRIMARY WEAPONS case WeaponIndex.MP5: graphic = new g_mp5(); name = "MP5"; ammoLeft = 120; ammoLoaded = 30; penetration = 1; range = 400; frames_per_bullet = 6; frames_per_reload = 1; spread = 8; damage = 15; sound = 400; knockback = 2; velocity = .90; shots = 1; clipSize = 30; primary = true; cost = 750; break; case WeaponIndex.SHOTGUN: graphic = new g_shotgun(); name = "Shotgun"; ammoLeft = 56; ammoLoaded = 7; penetration = 1; range = 250; frames_per_bullet = 60; frames_per_reload = .5; spread = 30; damage = 7; sound = 550; knockback = 3; velocity = .50; shots = 10; clipSize = 7; primary = true; cost = 1500; break; case WeaponIndex.AUTOSHOTGUN: graphic = new g_autoshotgun(); name = "Auto Shotgun"; ammoLeft = 56; ammoLoaded = 7; penetration = 1; range = 225; frames_per_bullet = 10; frames_per_reload = .5; spread = 35; damage = 10; sound = 600; knockback = 3; velocity = .5; shots = 12; clipSize = 7; primary = true; cost = 3000; break; case WeaponIndex.M4A1: graphic = new g_m4a1(); name = "M4A1"; ammoLeft = 120; ammoLoaded = 30; penetration = 2; range = 600; frames_per_bullet = 8; frames_per_reload = 1.1; spread = 5; damage = 15; sound = 400; knockback = 8; velocity = .90; shots = 1; clipSize = 30; primary = true; cost = 1700; break; case WeaponIndex.AK47: graphic = new g_ak47(); name = "AK-47"; ammoLeft = 120; ammoLoaded = 30; penetration = 3; range = 500; frames_per_bullet = 10; frames_per_reload = 1.2; spread = 8; damage = 20; sound = 600; knockback = 10; velocity = .90; shots = 1; clipSize = 30; primary = true; cost = 2100; break; case WeaponIndex.SNIPERRIFLE: graphic = new g_sniperrifle(); name = "Scout"; ammoLeft = 60; ammoLoaded = 10; penetration = 6; range = 800; frames_per_bullet = 55; frames_per_reload = 1.4; spread = 2; damage = 70; sound = 700; knockback = 10; velocity = 1.1; shots = 1; clipSize = 10; primary = true; cost = 2000; break; case WeaponIndex.MAGNUMSNIPER: graphic = new g_magsniper(); name = "AWM"; ammoLeft = 40; ammoLoaded = 10; penetration = 10; range = 1000; frames_per_bullet = 75; frames_per_reload = 1.23; spread = 1; damage = 120; sound = 730; knockback = 20; velocity = 1.2; shots = 1; clipSize = 10; primary = true; cost = 5000; break; case WeaponIndex.MACHINEGUN: graphic = new g_machinegun(); name = "M249"; ammoLeft = 300; ammoLoaded = 100; penetration = 3; range = 500; frames_per_bullet = 4; frames_per_reload = 5; spread = 20; damage = 20; sound = 500; knockback = 10; velocity = .90; shots = 1; clipSize = 100; primary = true; cost = 5500; break; } } public function fire() : void { SystemController.getInstance().soundService.localCall(SystemController.getInstance().userService.index + "|0"); } public function reload() : void { if (ammoLeft == 0 || ammoLoaded == clipSize) { return; } reloading = true; if (type == 4 || type == 5) { TweenLite.delayedCall(frames_per_reload, reloadShotgun); } else { TweenLite.delayedCall(frames_per_reload, reloadWeapon); } SystemController.getInstance().soundService.localCall(SystemController.getInstance().userService.index + "|1"); } private function reloadWeapon() : void { if(!reloading) { return } if (ammoLeft >= clipSize || ammoLeft >= (clipSize - ammoLoaded)) { ammoLeft -= (clipSize - ammoLoaded); ammoLoaded = ammoLoaded + (clipSize - ammoLoaded); } else { ammoLoaded = ammoLeft + ammoLoaded; ammoLeft = 0; } reloading = false; } private function reloadShotgun() : void { if (!reloading || (ammoLoaded == 7)) { reloading = false; return; } ammoLeft--; ammoLoaded++; if (ammoLoaded < clipSize) { reload(); } } public function empty() : void { SystemController.getInstance().soundService.localCall(SystemController.getInstance().userService.index + "|3"); } //this is a human readable to string function public function toString() : String { return ("Name: " + name + ", Ammo Loaded: " + ammoLoaded + ", Ammo Left: " + ammoLeft + ", Missed: " + misses + ", Shots Fired: " + shots_fired); } public function toServerString() : String { return (type + "," + ammoLoaded + "," + ammoLeft + "," + misses + "," + shots_fired); } } }