public RPGEffect(RPGEffect copy) { range = copy.range; durationType = copy.durationType; targetBuff = copy.targetBuff; targetAttack = copy.targetAttack; effectIsABuff = copy.effectIsABuff; trigger = copy.trigger; status = copy.status; location = copy.location; sourceObject = copy.sourceObject; targetObject = copy.targetObject; distance = copy.distance; radius = copy.radius; durationValue = copy.durationValue; minPower = copy.minPower; maxPower = copy.maxPower; m_Power = copy.Power; lastStart = copy.lastStart; lastPause = copy.lastPause; durationRemaining = copy.durationRemaining; repeatCount = copy.repeatCount; m_repeatDelay = copy.m_repeatDelay; m_lastRepeat = copy.m_lastRepeat; m_shouldReverse = copy.m_shouldReverse; powerType = copy.PowerType; }
void PanelAction_MouseClick(object sender, MouseEventArgs e) { RPGObject target = Session.thisSession.thisArea.GetObjectAt(e.Location); if (target == null) { // user clicked the ground if (e.Button == MouseButtons.Right) { LocationRightClick(e.Location); } else { LocationClick(e.Location); } } else { // then user selected this object if (e.Button == MouseButtons.Right) { ObjectRightClick(target); } else { ObjectClick(target); } } }
private void TargetObjectWithItemAction(ActionButton btn, RPGObject target) { TargetGroundWithItemAction(btn, target.Location); // use the button item on the target // do the effects. //foreach (RPGEffect effect in btn.Item.Effects) //{ // if (effect == null) // { // continue; // } // // make sure the target matches the requirements // if (effect.IsCorrectTarget(SelectedObject, target)) // { // target.AddEffect(effect); // Session.Print((SelectedObject as Actor).Name + " used " + btn.Item.Name); // // assuming a potion for now, the item gets consumed. // (SelectedObject as Actor).inventory.RemoveQuickItem(btn.Item); // btn.ClearItem(); // } // end if good target //} }
public int DistanceBetween(RPGObject a, Point p) { // closest edge of actor to point int dX; int dY; if (a.X > p.X) { dX = Math.Abs(a.X - p.X); } else if (a.X + a.Width < p.X) { dX = Math.Abs(p.X - a.X - a.Width); } else { dX = Math.Abs(a.X - p.X); } if (a.Y > p.Y) { dY = Math.Abs(a.Y - p.Y); } else if (a.Y + a.Height < p.Y) { dY = Math.Abs(p.Y - a.Y - a.Height); } else { dY = Math.Abs(a.Y - p.Y); } return((int)Math.Sqrt((dX * dX) + (dY * dY))); }
public bool ObjectOnPoint(RPGObject obj, Point p) { return(obj.X <= p.X && obj.X + obj.Width >= p.X && obj.Y <= p.Y && obj.Y + obj.Height >= p.Y); }
public void SetGroundItemsToActionPanel() { // get the items from the ground grid, and create a new item if (groundItems != null && groundItems.Count > 0) { // create a new item drop object RPGDrop newDrop = new RPGDrop(); int X = thisActor.Location.X; int Y = thisActor.Location.Y + 40; // +40 to look like ground. newDrop.Location = new Point(X, Y); for (int i = groundItems.Count - 1; i >= 0; i--) { // get each item from the ground collection RPGObject obj = groundItems[i] as RPGObject; // set its location to the current actor obj.Location = newDrop.Location; // add it to the drop item newDrop.AddItem(obj); // and remove this item from the groundItems collection groundItems.Remove(obj); } // add the item to the actionPanel's items. Session.thisSession.thisArea.AddObject(newDrop); } }
public FormItemDetails(RPGObject item) { thisItem = item; InitializeComponent(); this.lbl_Name.Text = item.Name; this.tb_Details.Text = CreateDetailText(); }
public bool ActorStandingNearPoint(RPGObject obj, Point p) { // point p has been adjusted already, use straight bool inX = (Math.Abs(obj.X - p.X) <= Math.Abs(obj.VX)); bool inY = (Math.Abs(obj.Y - p.Y) <= Math.Abs(obj.VY)); return(inX && inY); }
public bool ObjectsCollide(RPGObject a, RPGObject b) { Rectangle intersection = Rectangle.Intersect(new Rectangle(a.Location, a.Size), new Rectangle(b.Location, b.Size)); return(intersection.IsEmpty == false); }
public RPGAction(ActionType t, RPGObject targetObject) { type = t; NeedsUpdating = true; UpdateFrequency = DEFAULT_UPDATE_FREQUENCY; lastUpdate = DateTime.Now; target = targetObject; destination = targetObject.Location; }
public bool IsCorrectTarget(RPGObject source, RPGObject target, Point targetLocation) { if (source == null || target == null) { return(false); } bool result = false; RPGCalc calc = new RPGCalc(); switch (range) { case (EffectRange.Self): { result = (source == target); break; } case (EffectRange.Target): { // target is roughly at location result = calc.ObjectOnPoint(target, targetLocation); break; } case (EffectRange.Touch): { // target within touch distance int d = calc.DistanceBetween(source, target); result = (d <= RPGCalc.DEFAULT_TOUCH_RANGE); break; } case (EffectRange.Area): { // target within item distance int d = calc.DistanceBetween(source, target); result = (d <= this.distance); break; } case (EffectRange.TargetArea): { // target within item distance and radius int d = calc.DistanceBetween(target, targetLocation); result = (d <= this.radius); break; } default: { break; } } // end switch return(result); }
private bool AddItemToQuick(RPGObject item) { bool result = false; if (item != null && item.isOfType(typeof(RPGItem))) { result = thisActor.inventory.AddQuickItem(item as RPGItem); LoadQuickGrid(thisActor); } return(result); }
private bool AddItemToPack(RPGObject item) { bool result = false; if (item != null && thisActor.inventory.AddItem(item)) { LoadPackGrid(thisActor); result = true; } return(result); }
public void RemoveObject(RPGObject obj) { for (int i = 0; i < RPGObjects.Length; i++) { if (RPGObjects[i] != null) { if (RPGObjects[i] == obj) { RPGObjects[i] = null; return; } } } }
void btnEquip_Click(object sender, EventArgs e) { // move selected pack item to body, at correct slot // if already equipped, then switch locations. RPGObject item = GetSelectedItemFromPack(); // now, check if body already has an item at that slot if (item == null) { MessageBox.Show("No item selected from pack to equip."); return; } else if (item.isOfType(typeof(RPGItem)) == false) { MessageBox.Show("This item type cannot be equipped."); return; } else { // check if destination slot is already filled if (thisActor.inventory.GetBodyItem(((RPGItem)item).Slot) != null) { // find currently equipped item and remove it RPGItem currentlyEquippedItem = thisActor.inventory.GetBodyItem(((RPGItem)item).Slot); if (AddItemToPack(currentlyEquippedItem)) { RemoveItemFromBody(currentlyEquippedItem); } else { MessageBox.Show("Unable to add equipped item back into pack."); return; } } // end it slot is already filled else { // add new item to body if (AddItemToBody(((RPGItem)item), ((RPGItem)item).Slot)) { RemoveItemFromPack(item); } else { MessageBox.Show("Unable to equip item."); } } // end else - destination slot empty } // end else - item ok }
public RPGObject RemovePackItem(int packSlotIndex) { RPGObject obj = GetPackItem(packSlotIndex); if (obj != null) { PackItems[packSlotIndex] = null; return(obj); } else { return(null); } }
private void LocationClick(Point loc) { if (SelectedObject == null) { // then user has chosen to click on the ground for some reason... GroundClicked(loc); } else { // then user has selected the ground, unselect our current object SelectedObject.IsSelected = false; SelectedObject = null; } }
private void RemoveItemFromPack(RPGObject item) { // since the item can be anywhere, check all of them. for (int i = 0; i < Inventory.PACK_SIZE; i++) { if (thisActor.inventory.GetPackItem(i) == item) { thisActor.inventory.RemovePackItem(i); break; } } LoadPackGrid(thisActor); }
private void LoadPackRow(RPGObject item) { if (item == null) { return; } DataRow row = dtPackItems.NewRow(); row[0] = item.Name; row[1] = GetItemType(item); if (item.isOfType(typeof(RPGItem))) { row[2] = (item as RPGItem).Description; } dtPackItems.Rows.Add(row); }
public int DistanceBetween(RPGObject a, RPGObject b) { int dX = Math.Abs(a.X - b.X); int dY = Math.Abs(a.Y - b.Y); if (dX > a.Width) { dX -= a.Width; } if (dY > a.Height) { dY -= a.Height; } return((int)Math.Sqrt((dX * dX) + (dY * dY))); }
/// <summary> /// Calculates the location (Point) that is towards the target /// in order to be within the given range /// </summary> /// <param name="source"></param> /// <param name="Range"></param> /// <param name="target"></param> /// <returns></returns> public Point PointToBeInRange(Actor source, int Range, RPGObject target) { // so, use the distance between and the actor's range to figure where the point needs to be. int distanceX = target.X - source.X; int distanceY = target.Y - source.Y; int diagDistance = (int)Math.Sqrt(distanceX * distanceX + distanceY * distanceY); // diagDistance is the entire distance between the two, we only need enough to get in range. diagDistance -= Range; // now diagDistance is the distance between source and target IN RANGE double angle = Math.Atan((double)distanceY / (double)distanceX); int changeX = (int)(Math.Cos(angle) * diagDistance * 1.1); // 1.1 = get inside range int changeY = (int)(Math.Sin(angle) * diagDistance * 1.1); // sometimes the x value turns out backwards, so make a general // sweeping assumption to check for the correct direction. if (source.X > target.X) { // changeX needs to be negative changeX = -Math.Abs(changeX); } else if (source.X < target.X) { // changeX needs to be postive changeX = Math.Abs(changeX); } // check the y value too. if (source.Y > target.Y) { // changeY needs to be negative changeY = -Math.Abs(changeY); } else if (source.Y < target.Y) { // changeY needs to be positive changeY = Math.Abs(changeY); } return(new Point(source.X + changeX, source.Y + changeY)); }
void btnPickup_Click(object sender, EventArgs e) { // move selected ground item to pack RPGObject item = GetSelectedItemFromGround(); if (item == null) { MessageBox.Show("No item selected from ground."); } else if (AddItemToPack(item)) { RemoveItemFromGround(item); } else { MessageBox.Show("unable to pick up item from ground."); } }
void btnQuickRemove_Click(object sender, EventArgs e) { // move selected ground item to pack RPGObject item = GetSelectedItemFromQuick(); if (item == null) { MessageBox.Show("No item selected from pack "); } else if (AddItemToPack(item)) { RemoveItemFromQuick(item); } else { MessageBox.Show("Could not move item from quick to pack."); } }
void btnQuickAdd_Click(object sender, EventArgs e) { // move selected pack item to ground RPGObject item = GetSelectedItemFromPack(); if (item == null) { MessageBox.Show("No item selected from pack to add to quick items."); } else if (AddItemToQuick(item)) { RemoveItemFromPack(item); } else { MessageBox.Show("Could not add item to Quick Items"); } }
void btnDrop_Click(object sender, EventArgs e) { // move selected pack item to ground RPGObject item = GetSelectedItemFromPack(); if (item == null) { MessageBox.Show("No item selected from the pack to drop."); } else if (AddItemToGround(item)) { RemoveItemFromPack(item); } else { MessageBox.Show("Unable to drop item to ground."); } }
public bool AddObject(RPGObject obj) { int s = GetObjSlot(); if (s > -1) { RPGObjects[s] = obj; if (obj.isOfType(typeof(Actor))) { (obj as Actor).ResetStats(); } return(true); } else { return(false); } }
private void ObjectRightClick(RPGObject obj) { if (SelectedObject == null) { // right click something first? } else { //if (SelectedObject != obj) //{ // // right clicked a different object TargetObject(obj); //} //else //{ // // right clicked same object again? //} } }
private RPGObject GetSelectedItemFromPack() { if (dgvPack.SelectedRows.Count != 1) { return(null); } string selDesc = dgvPack.SelectedRows[0].Cells[2].Value.ToString(); for (int i = 0; i < Inventory.PACK_SIZE; i++) { RPGObject item = thisActor.inventory.GetPackItem(i); if (item != null && (item as RPGItem).Description == selDesc) { return(item); } } return(null); }
public bool AddItem(RPGObject obj) { if (obj.isOfType(typeof(RPGDrop))) { RPGObject[] objs = ((RPGDrop)obj).GetItems(); for (int i = 0; i < objs.Length; i++) { AddItem((RPGItem)objs[i]); } return(true); } else if (obj.isOfType(typeof(RPGItem))) { return(AddPackItem((RPGItem)obj)); } else { // don't recognize item type. return(false); } }
private string GetItemType(RPGObject item) { // set 'type' conditionally. string type = item.GetType().ToString(); switch (type) { case ("RPG.RPGWeapon"): { // then get the weapon class/type return(Enum.GetName(typeof(RPGWeapon.WeaponClass), ((RPGWeapon)item).weaponClass)); //break; } case ("RPG.Projectile"): { return(Enum.GetName(typeof(Projectile.ProjectileType), ((Projectile)item).type)); //break; } case ("RPG.RPGArmor"): { // then get the armor class/type return(Enum.GetName(typeof(RPGArmor.ArmorClass), ((RPGArmor)item).Class)); //break; } case ("RPG.RPGPotion"): { return("Potion"); //break; } default: { return(type); } } // end switch }