Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Questions and Supports

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 12-24-2014, 11:45 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 88,285
Kyttias is on a distinguished road
Question Holiday Shops

Is it possible to have items be in shops only during certain time periods? For example - if we wanted to create holiday items?

I think this would be a great addition to the site and I was hoping for a shove in the right direction before I start. There are three different ideas I have, but I'm not sure which one I'll share to the community (hopefully all three!):

1- An ordinary shop that, in addition to it's normal stock, also has some stock only available on holidays. (I'd like to do this, because the technique would be good for what I want to do with my shops.) - Medium

2- A holiday-only shop (ala Flight Rising's "Festive Favors" shop, only without the unique currency, yet anyway) that has different stock entirely based on an event period and is otherwise closed for business. It is open on every holiday, but only holidays, and has stock based on that holiday only. (I'd like this to be semi-automated, that way items can be ready to go in advance and I don't have to be online to open the shop at midnight manually. Just visiting the shop directory or the shop's link directly would be enough to trigger a rollover from Closed to Open status, at least on appropriate days) - Hard

3- A single holiday shop that does not have alternate stock and is only open for one, single event. (I find this to be the easiest and probably would not need help with implementing it.) - Easy

All of this also might leans towards the start of shops that 'stock' in a way more like existing games do, down the road, anyway. You know, limited quantities of certain items and they restock based on set intervals and a slightly random array?

I'd like to see more done with shops in the future. ^^
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.

Last edited by Kyttias; 12-24-2014 at 11:49 PM.
Reply With Quote
  #2  
Old 12-25-2014, 01:12 AM
parayna's Avatar
parayna parayna is offline
Member
 
Join Date: May 2013
Location: Devon, UK
Posts: 342
Gender: Female
Credits: 16,488
parayna is on a distinguished road
Default

*jumps in to say 'great ideas' and then jumps out again* ;)
Reply With Quote
  #3  
Old 12-25-2014, 10:28 AM
Abronsyth's Avatar
Abronsyth Abronsyth is offline
A Headache Embodied
 
Join Date: Aug 2011
Location: NY
Posts: 1,011
Gender: Male
Credits: 113,363
Abronsyth is on a distinguished road
Default

well, for having the item only available on Holidays...you could probably look in at the function that allows you to have a pet released at a certain date...maybe take a look at that code and piece it out a bit.

You could also work that out with Item classes. I was going to look into classes myself, once I work on adding a Stats feature, but I don't know anything about them right now, so can't be of much help, apologies.

Happy Holidays, at any rate :)
__________________
My Mods Site (1.3.4, 2020 Mods)
Reply With Quote
  #4  
Old 12-25-2014, 04:32 PM
IntoRain's Avatar
IntoRain IntoRain is offline
Moderator
 
Join Date: Jul 2013
Location: Portugal
Posts: 461
Gender: Female
Credits: 19,372
IntoRain is on a distinguished road
Default

I coded something similar to #2, it should work properly but if you find a bug tell me.

How it works:

You add a new table to your database with the events your site has. These events have a start and end date. The good thing to this table is that you can use these events for other things you want to change in your site during holidays!
Then you associate your "holiday" shops with the various events they are open in, in the database. Then you associate your holiday items with a holiday shop and an event as well.

When the shops are displayed, the server checks if any of the events they are associated with, if any, are active. If not, the shop is closed. If one is active, the shop is open. Shops without any events associated work like normal shops. Entering the shop, the server loads the items that belong to that shop and to the current event.

Important: I only did this to the Itemshop so far, not Adoptshop

Important: I did no Admincp option for this, so you will have to manually edit the database with the stuff you want. I will try to add this mod to the Admincp sometime later

Also guys feel free to add in the stuff missing yourself or make any changes at all to fit your site and your ideas.


How to do this:

Database

1) First, add a new table to your database called [prefix]_events. Please note [prefix] is your database prefix, what all your tables begin with. For example, all my tables begin with 'adopts', because it's mysidia's default upon installation.

Fields:
  • eid -> it's an int, a primary key, can't be null, set it to auto_increment (A_I)
  • name -> The name of your event. It's a varchar, can be null and default is "NULL"
  • startson -> When your event starts. It's a varchar, at least size 5
  • endson -> When your event ends. It's a varchar, at least size 5

Note: Both startson and endson will be in the format Day-Month. If you switch to Month-Day some functions won't work anymore.

Note2: If your startson is 24-12 (24 December) and endson is 28-12 (28 December), that means the shop will run on the 24, 25, 26 and 27. Once it's 28, the shop will be inactive.

Example:
Below is the structure and contents of my table adopts_events.


2) Now go to your table [prefix]_items and add the following column:
  • eventid -> it's an int, can be null and default is -1

Items with an eventid of -1 don't belong in any event.
Items with an eventid > 0 belong in an event.

Example:
For example, in the image above, you can see the eid of my Christmas event is 1. So I added an item to a store called "Holliday Items" with an eventid of 1. That means that item will be sold in the store Holliday Items only when it's Christmas (eventid = 1). If I had put an eventid of 3, it would appear on Valentine's Day, etc. It depends on the events you added to your [prefix]_events table and their eid.



3) Now go to your [prefix]_shops table and add in this new column:
  • events -> varchar, can be null and default is 'none'

In this column, you will put event IDs (eid from [prefix]_events table) separated by commas (no spaces between them). If the shop is not event-only, put 'none' instead.

Example:

For example, if I wanted a shop open on Christmas and Halloween, since the eid for those events are 1 and 2 in my events table, I have to put "1,2" on that column. If I just wanted Christmas, I'd put "1". If I wanted all my 3 events I created I have to put "1,2,3".




Files

1) Create the file class_event.php (inside classes folder) with these contents:

PHP Code:
<?php

use Resource\Native\String;
use 
Resource\Native\Object;

class 
Event extends Object{

    public 
$eid;
    public 
$name;
    public 
$startson;
    public 
$endson;
  
    public function 
__construct($eid){      
    
$mysidia Registry::get("mysidia");
    
$row $mysidia->db->select("events", array(), "eid ='{$eid}'")->fetchObject();

    if(!
is_object($row)) throw new Exception("Invalid Event specified");
        
// loop through the anonymous object created to assign properties
        
foreach($row as $key => $val){
            
$this->$key $val;         
        }
    }

  public function 
isActive() {

     
$isActive false;
     
$startson_s explode('-'$this->startson);
     
$endson_s explode('-'$this->endson);
     
$today date('d-m');     
     
$today_s explode('-'$today);
          
      if(
$startson_s[1] == $endson_s[1]){
         if(
$today_s[1] == $startson_s[1] && $today_s[0] >= $startson_s[0] && $today_s[0] < $endson_s[0]){
                 
$isActive true;
         }
      }
      else if(
$startson_s[1] < $endson_s[1]){
          
          if(
$today_s[1] >= $startson_s[1] && $today_s[1] <= $endson_s[1]){
              if(
$today_s[1] == $startson_s[1]){
                  if(
$today_s[0] >= $startson_s[0])
                      
$isActive true;
              }
              else if(
$today_s[1] == $endson_s[1]){
                  if(
$today_s[0] < $endson_s[0])
                      
$isActive true;
              }
             else
                    
$isActive true;          
          }
                    
      }    
      else {
      
          if(
$today_s[1] >= $startson_s[1] || $today_s[1] <= $endson_s[1]){
              if(
$today_s[1] == $startson_s[1]){
                  if(
$today_s[0] >= $startson_s[0])
                      
$isActive true;
              }
              else if(
$today_s[1] == $endson_s[1]){
                  if(
$today_s[0] < $endson_s[0])
                      
$isActive true;
              }
             else
                    
$isActive true;          
          }      
      
      }
         
     return 
$isActive;
  }
  
}
?>
The isActive() function is pretty messy, if anyone wants to reduce it, I'd appreciate it xD

2) Edit the file class_item.php like this:

class_item.php

PHP Code:
<?php

use Resource\Native\Object;

class 
Item extends Model{
  
// The item class.

    
public $id;
    public 
$category;
    public 
$itemname;
    public 
$description;
    public 
$imageurl;
    public 
$function;
    public 
$target;
    public 
$shop;
    public 
$price;
    public 
$chance;
    public 
$cap;
    public 
$tradable;
    public 
$consumable;

    public 
$eventid;//add this line here!
(...)
3) Edit the file class_itemshop.php like below. In case you can't copy the whole code, all changes are commented with "add this", so look for them and compare to your existing file to add them in.

class_itemshop.php
PHP Code:
<?php

use Resource\Collection\LinkedList;

class 
Itemshop extends Model{

    public 
$sid;
    public 
$category;
    public 
$shopname;
    public 
$shoptype;
    public 
$description;
    public 
$imageurl;
    public 
$status;
    public 
$restriction;
    public 
$salestax;
    public 
$events;//add this
    
public $events_array;//add this
    
public $active_event;//add this
    
public $items;
    protected 
$total 0;
  
    public function 
__construct($shopname){
        
// Fetch the database info into object property      
        
$mysidia Registry::get("mysidia");
        
$row $mysidia->db->select("shops", array(), "shopname ='{$shopname}'")->fetchObject();
        if(!
is_object($row)) throw new Exception("Invalid Shopname specified");
      
        
// loop through the anonymous object created to assign properties
        
foreach($row as $key => $val){
            
$this->$key $val;     
        }

    
//add this here, this has to be before the getitemnames()!
    
$this->active_event = -1;    
    if(
$this->events != 'none') {
           
$this->fillEventsArray();
        
$this->checkForEvent();
    }
    
        
$this->items $this->getitemnames();
        
$this->total = (is_array($this->items))?count($this->items):0;
        
    }

    public function 
getcategory(){
        
$mysidia Registry::get("mysidia");
        
$stmt $mysidia->db->select("shops", array(), "category ='{$this->category}'");
        
$cate_exist = ($row $stmt->fetchObject())?TRUE:FALSE;     
        return 
$cate_exist;
    }
  
    public function 
getshop(){  
        
$mysidia Registry::get("mysidia");
        if(empty(
$this->shopname)) $shop_exist FALSE;
        else{
            
$stmt $mysidia->db->select("shops", array(), "shopname ='{$this->shopname}'");
            
$shop_exist = ($row $stmt->fetchObject())?TRUE:FALSE;    
        }
        return 
$shop_exist;
    }
  
    public function 
getitemnames(){
          if(!
$this->items){
            
$mysidia Registry::get("mysidia");
                
            
////add this 
            
if($this->events != 'none'
                
$stmt $mysidia->db->select("items", array("itemname"), "shop ='{$this->shopname}' and eventid='{$this->active_event}'");
            else
                
$stmt $mysidia->db->select("items", array("itemname"), "shop ='{$this->shopname}'");
            
            
$items = array();
        
            while(
$item $stmt->fetchColumn()){
                
$items[] = $item;
            }
            return 
$items;
        }
        else return 
$this->items;
    }
  
    public function 
gettotal(){  
        return 
$this->total;
    }
  
    public function 
display(){
        
$mysidia Registry::get("mysidia");
        
$document $mysidia->frame->getDocument();              
        
$document->addLangvar($mysidia->lang->select_item);
       
      
        if(
$this->gettotal() == 0){
            
$document->addLangvar($mysidia->lang->empty);
            return 
FALSE;
        }     
          
        
$itemList = new TableBuilder("shop");
        
$itemList->setAlign(new Align("center""middle"));
        
$itemList->buildHeaders("Image""Category""Name""Description""Price""Buy");    
        
$itemList->setHelper(new ShopTableHelper);
      
        foreach(
$this->items as $stockitem){
              
$item $this->getitem($stockitem);
            
$cells = new LinkedList;         
            
$cells->add(new TCell(new Image($item->imageurl)));
            
$cells->add(new TCell($item->category));
            
$cells->add(new TCell($item->itemname));
            
$cells->add(new TCell($item->description));
            
$cells->add(new TCell($item->price));
            
$cells->add(new TCell($itemList->getHelper()->getItemPurchaseForm($this$item)));
            
$itemList->buildRow($cells);
        }      
        
$document->add($itemList);  
    }
  
    public function 
getitem($itemname){
      return new 
StockItem($itemname);
    }
  
    public function 
purchase(Item $item){
        
$mysidia Registry::get("mysidia");
        echo 
$item->eventid;
        if(
$item->owner != $mysidia->user->username) Throw new NoPermissionException('Something is very very wrong, please contact an admin asap.');
        else if((
$this->events != 'none') && ($item->eventid != $this->active_event)) throw new Exception("This item doesn't exist.");//add this
        
else{
            
$item->quantity $mysidia->input->post("quantity");
            
$cost $item->getcost($this->salestax$item->quantity);
            
$moneyleft $mysidia->user->money $cost;
            if(
$moneyleft >= and $item->quantity 0){    
                
$purchase $item->append($item->quantity$item->owner);
                
$mysidia->db->update("users", array("money" => $moneyleft), "username = '{$item->owner}'");            
                
$status TRUE;
            }            
            else throw new 
InvalidActionException($mysidia->lang->money);
        }
        return 
$status;
    }
  
    public function 
rent($item$period){

    }
  
    public function 
execute($action){
    
    }
  
      protected function 
save($field$value){
        
$mysidia Registry::get("mysidia");
        
$mysidia->db->update("shops", array($field => $value), "sid='{$this->sid}' and shoptype = 'adoptshop'");
    }  

   
//add this
   
public function fillEventsArray(){       
       
$i 0;
       
$events explode(','$this->events);
       foreach(
$events as $event_id){
           
$event = new Event($event_id);
           
$this->events_array[$i] = $event;
           
$i++;
       }

   }
   
   
//add this
   
public function checkForEvent(){

       foreach(
$this->events_array as $event){
           if(
$event->isActive()){
               
$this->status 'open';           
               
$this->active_event $event->eid;
               return 
true;
           }
       }
           
    
$this->status 'closed';       
       
$this->active_event = -1;
       return 
false;
   }
   
}
?>
Please note that, with this mod, one shop can have multiple event IDs associated (separated by commas like 1,2,3), but items cannot. Items can only have one event associated or -1 in case they aren't associated with events.

I tested with a few different dates, but if you detect any bugs please tell me.
__________________


asp.net stole my soul.

Last edited by IntoRain; 12-25-2014 at 04:41 PM.
Reply With Quote
  #5  
Old 12-25-2014, 06:11 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 88,285
Kyttias is on a distinguished road
Default

Wow! Looks great! I'll test it out right away.

And if I wanted a one-day only event, the start date would be the day of the event, and the end date should be set to the day after? Right?
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.
Reply With Quote
  #6  
Old 12-25-2014, 06:59 PM
IntoRain's Avatar
IntoRain IntoRain is offline
Moderator
 
Join Date: Jul 2013
Location: Portugal
Posts: 461
Gender: Female
Credits: 19,372
IntoRain is on a distinguished road
Default

Quote:
Originally Posted by Kyttias View Post
Wow! Looks great! I'll test it out right away.

And if I wanted a one-day only event, the start date would be the day of the event, and the end date should be set to the day after? Right?
Great! If you find any bug or mistake let me know!

Yes, that would be it ^^
__________________


asp.net stole my soul.
Reply With Quote
Reply

Tags
holiday shop


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Shops voni Questions and Supports 3 04-22-2015 02:01 PM
Help !! Shops not appearing é.è kitty08 Feedback and Suggestions 3 12-31-2014 11:15 AM
Help with shops. Nieth Questions and Supports 5 11-26-2013 05:15 AM
Forum Shops? AlexC Feedback and Suggestions 6 05-09-2012 03:28 PM
Again Shops RoconzaArt Questions and Supports 10 01-17-2011 04:32 PM


All times are GMT -5. The time now is 03:49 AM.

Currently Active Users: 9768 (0 members and 9768 guests)
Threads: 4,080, Posts: 32,024, Members: 2,016
Welcome to our newest members, jolob.
BETA





What's New?

What's Hot?

What's Popular?


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
vBCommerce I v2.0.0 Gold ©2010, PixelFX Studios
vBCredits I v2.0.0 Gold ©2010, PixelFX Studios
Emoticons by darkmoon3636